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?
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