konstantinbueschel
11/25/2016 - 3:55 PM

Force options menu in ActionBar on devices which have hardware menu button - From http://stackoverflow.com/questions/26010876/options-menu-d

Force options menu in ActionBar on devices which have hardware menu button - From http://stackoverflow.com/questions/26010876/options-menu-does-not-appear-in-action-bar-on-some-devices/26011059#26011059

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) {}