ToolBar inflateMenu 不生效

by seaicelin
转载请注明出处:http://blog.csdn.net/amd123456789/article/details/52474984

在使用ToolBar的时候,发现调用

Toolbar.inflateMenu(R.menu.toolbar_menu);

一直显示不出ToolBar右上角的图标。其中menu文件如下:

<?xml version="1.0" encoding="utf-8"?>

然而,发现不调用ToolBar本身的接口,调用Activity本身创建menu的接口却可以显示!!

//设置ToolBar的选项@Overridepublic boolean onCreateOptionsMenu(Menu menu) {    //MenuInflater inflater = getMenuInflater();    //inflater.inflate(R.menu.toolbar_menu, menu);    return super.onCreateOptionsMenu(menu);}

这个问题纠结,查了很久!总算找到答案了:

http://stackoverflow.com/questions/26511981/toolbar-inflatemenu-seems-to-do-nothing

If you are calling setSupportActionBar() you don’t need to use toolbar.inflateMenu() because the Toolbar is acting as your ActionBar. All menu related callbacks are via the default ones. The only time you need to call toolbar.inflateMenu() is when you are using the Toolbar as a standalone widget.

意思就是说,要想让Toolbar本身的inflateMenu生效,则必须删去这两句代码!!!

setSupportActionBar(toolbar);getSupportActionBar().setDisplayHomeAsUpEnabled(true);

This is the answer!!

更多相关文章

  1. Ubuntu为安装的软件添加启动图标
  2. Android(安卓)中关于属性动画的一些思考,或许能为你解决一定的性
  3. Android(安卓)之ExpandableListView几个特殊的属性
  4. Android(安卓)volley封装实践其二
  5. 基于32bit系统编译Android(安卓)2.3
  6. Android(安卓)的系统属性(SystemProperties)设置分析
  7. Android(安卓)textview获取选中的内容
  8. android Studio 引用fresco 出现的问题
  9. Android(安卓)AIDL详解

随机推荐

  1. Analyzing Android(安卓)Malware
  2. Android(安卓)Gradle manifestPlaceholde
  3. android top 10 library1
  4. 如何在activity中控制屏幕点亮与关闭
  5. Android中http请求(C# MVC接收)
  6. Android如何使用WebView访问https的网站
  7. android零碎要点---android开发者的福音,5
  8. Android禁止横竖屏和解决切换屏幕时重启A
  9. android 每天定时提醒功能实现
  10. 从android游戏框架看其生命周期