Options Menu does not appear in Action Bar on some devices

六眼飞鱼酱① 提交于 2019-12-07 13:24:11

问题


I have an options menu in the action bar, and it does not appear on certain devices which have hardware menu button. I must make it appear in the action bar despite having a hardware button... How can I do it?


回答1:


Put this in your onCreate method:

try {
    ViewConfiguration config = ViewConfiguration.get(this);
    Field menuKeyField = ViewConfiguration.class
            .getDeclaredField("sHasPermanentMenuKey");
    if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
    }
} catch (Exception ex) {
}


来源:https://stackoverflow.com/questions/26010876/options-menu-does-not-appear-in-action-bar-on-some-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!