I want to show a overflow menu in toolbar(AppCompat-v7:22.1.1), below is my menu_main.xml.
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"> <item android:id="@+id/action_search" android:title="@string/action_search" android:icon="@mipmap/ic_menu_search" android:orderInCategory="100" android:actionViewClass="android.widget.SearchView" app:showAsAction="ifRoom"/> <item android:id="@+id/menu_group_chat" android:title="@string/menu_group_chat" android:icon="@mipmap/ic_menu_groupchat" /> <item android:id="@+id/menu_add_friend" android:title="@string/menu_add_friend" android:icon="@mipmap/ic_menu_add_friend" />
运行我的应用程序后,没有显示菜单项的图标,然后我想这solution,在我的Activty添加替代方法onMenuOpened()(范围是从AppCompatActivity),
After running my app, the icon of menu item is not displayed, then I tried this solution, add an override method onMenuOpened() in my Activty(extends from AppCompatActivity),
@Override public boolean onMenuOpened(int featureId, Menu menu) { if(menu!=null){ if(menu.getClass().getSimpleName().equals("MenuBuilder")){ try { Method m = menu.getClass().getDeclaredMethod( "setOptionalIconsVisible", Boolean.TYPE); m.setAccessible(true); m.invoke(menu, true); } catch (Exception e) { e.printStackTrace(); } } } return super.onMenuOpened(featureId, menu); }
但在运行此演示后,我发现,仍然没有显示的图标。
But after running this demo, I find that the icon is still not displayed.
从这个报告的问题,我知道这AppCompatActivity.onMenuOpened不叫更多的22.x暂时,但奇怪的是,当我点击Genymotion硬件菜单键,菜单出现在底部,并带有图标,
From this reported issue, I know that AppCompatActivity.onMenuOpened is not called any more in 22.x, but it's odd that when I click the hardware menu key in Genymotion, the menu appear at the bottom and with the icon,
关闭菜单后,我再次点击工具栏上的溢出按钮,这些图标菜单显示,
after closing the menu, I click the overflow button in the toolbar again, these icons in menu appear,
这是多么奇怪!为什么出现这种情况?
how strange it is! Why this happens?
对于 AppCompactActivity你可以把这张支票上的在prepareOptionsPanel ()代替。
@Override protected boolean onPrepareOptionsPanel(View view, Menu menu) { if (menu != null) { if (menu.getClass().getSimpleName().equals("MenuBuilder")) { try { Method m = menu.getClass().getDeclaredMethod( "setOptionalIconsVisible", Boolean.TYPE); m.setAccessible(true); m.invoke(menu, true); } catch (Exception e) { Log.e(getClass().getSimpleName(), "onMenuOpened...unable to set icons for overflow menu", e); } } } return super.onPrepareOptionsPanel(view, menu); }
相关推荐
买买提·肉孜(2023最新买买提·肉孜百科介绍)
社会主义劳动(2023最新社会主义劳动百科介绍)
抛光(磨擦使物体光滑的过程)
詹姆士志场(詹姆士志场)
刘玉水(漳浦烈士-刘玉水)
邬捷飞(伪县协和会青年训练团负责人)
建星路(建星路)
使用按键A,Ctrl + A键,按Ctrl + C和Ctrl + V的最大字符数按键、字符
为什么它永远是一个空值?是一个
如何在每个组之前的分组项目页面中插入图像列表?图像、页面、项目
什么是科幻小说_什么是科幻小说
苹果7s参数配置_苹果12pro参数配置 苹果12参数配置
橘子树苗种植方法_橘子的种植时间与方法 橘子树苗种植方法
魔兽世界怀旧服30级去哪升级 你也是在这升级吗_魔兽世界怀旧服30
泡泡玛特盲盒选择技巧 泡泡玛特盲盒选择技巧大总结_怎么泡发干海
月经不走怎么回事_月经不走怎么办
春季是私处炎症高发季_春季是小儿肺炎的高发季
头发少的话怎么样可以增多呢?_头发少吃什么好
精浊是什么原因引起的,有哪些明显症状?_射精后尿道疼痛的原因是什
怎样治疗气滞血瘀?这六种方法效果非常好_中药治疗尿毒症,此种方法效
最新文章
新景花园(2023最新新景花园百科介绍)
伊万•什梅廖夫(伊万•什梅廖夫)
胎产证治(胎产证治)
富源村(黑龙江省大庆市大同区双榆树乡下辖村)
想要和你谈恋爱(欧阳尚尚、海青合唱的流行歌曲)
国投晋城能源投资有限公司(中国能源行业领先企业)
什么是默认的超时HttpTransportSE的?HttpTransportSE
杜淳印小天到底什么事件_杜淳老婆王灿1992多高 杜淳老婆王灿到底
女人一举动男人永远无法抗拒_10种为爱“犯贱”的女人 男人永远不
白细胞3万多是否正常呢_正常精子是什么样的? 十个指标告诉你
内风湿关节炎严重吗_内风湿关节炎的症状
辣炒木耳肉丝的做法_辣炒鸡胗的做法
吓!这竟成了同居的尽头_惊!冰棍儿融化后 竟成了一摊胶状物
如何治好脱发呢_真的不要再浪费钱了,一片叶子就能治好脱发
法令纹面相图解大全_好命女面相的七大特征
白血球低是怎么回事(总胆固醇偏高是怎么回事_总胆固醇偏高知识大
怎样破解别人的qq相册密码(如何查看qq空间加密相册)
幸福的近义词有什么(幸福的同义词是什么?)
钱柜KTV小包房多少钱一小时?(小包房多少钱ktv)
西装礼仪(西装礼仪的三个三原则)