Android中ActionBar和ToolBar添加返回箭头的实例代码
2017-09-11 09:25
911 查看
1.ActionBar添加返回箭头
//onCreate方法中 ActionBar actionBar = this.getSupportActionBar(); actionBar.setTitle("搜索功能"); actionBar.setDisplayHomeAsUpEnabled(true); //activity类中的方法 @Override public boolean onOptionsItemSelected(MenuItem item) { if(item.getItemId() == android.R.id.home) { finish(); return true; } return super.onOptionsItemSelected(item); }
在这里,ActionBar引入包:import android.support.v7.app.ActionBar;
2. ToolBar添加返回箭头
代码如下:
//onCreate函数中 Toolbar mToolbarTb = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(mToolbarTb); getSupportActionBar().setDisplayHomeAsUpEnabled(true); //activity类中的方法 //添加点击返回箭头事件 @Override public boolean onOptionsItemSelected(MenuItem item) { if(item.getItemId() == android.R.id.home) { finish(); return true; } return super.onOptionsItemSelected(item); }
总结
以上所述是小编给大家介绍的Android中ActionBar和ToolBar添加返回箭头的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
您可能感兴趣的文章:
- Android动态修改ToolBar的Menu菜单示例
- Android中Toolbar随着ScrollView滑动透明度渐变效果实现
- Android折叠式Toolbar使用完全解析(CollapsingToolbarLayout)
- Android自定义Toolbar使用方法详解
- Android ToolBar控件详解及实例
- Android自定义ActionProvider ToolBar实现Menu小红点
- 解决Android V7后自定义Toolbar、ActionBar左侧有空白问题
- Android5.0+ CollapsingToolbarLayout使用详解
- Android ToolBar整合实例使用方法详解
- android ToolBar的简单使用
相关文章推荐
- Android中ActionBar和ToolBar添加返回箭头
- Android之Toolbar的三个问题:修改左边箭头颜色、怎样修改右边以及子activity中的toolbar添加返回箭头
- Android之Toolbar的三个问题:修改左边箭头颜色、怎样修改右边以及子activity中的toolbar添加返回箭头
- Android 应用按返回键退向后台运行实例代码
- Android Actionbar 添加返回按钮
- Android自定义View实现箭头沿圆转动实例代码
- Android仿微信朋友圈添加图片的实例代码
- android ListView内数据的动态添加与删除实例代码
- Android 活动条ActionBar的详解及实例代码
- Android微信朋友圈向微信主界面返回在ActionBar中箭头按钮的实现
- Android View添加 Listener 实例代码
- Android仿微信右滑返回功能的实例代码
- Android Toolbar自定义标题标题居中的实例代码
- Toolbar的三个问题:修改左边箭头颜色、怎样修改右边以及子activity中的toolbar添加返回箭头
- 关于ToolBar和Actionbar左上角返回箭头的问题
- Android 动态添加Fragment的实例代码
- Toolbar的三个问题:修改左边箭头颜色、怎样修改右边以及子activity中的toolbar添加返回箭头
- Android—JNI调用简单实例解析/Eclipse无添加NDK的选项/JNI返回数组
- Android 窗口添加机制系列3-代码实例
- Android中双击返回键退出应用实例代码