How to force action bar overflow icon to show

Congratulations! You won!

As of Android 4.4, the … affordance in the action bar will be there, regardless of whether the device has a physical MENU button or not. Google’s current Compatibility Definition Document now comes out a bit more forcefully against having a dedicated MENU button.

The hack that developers have used in the past, to get this behavior, is:

try {
  ViewConfiguration config = ViewConfiguration.get(this);
  Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");

  if (menuKeyField != null) {
    menuKeyField.setAccessible(true);
    menuKeyField.setBoolean(config, false);
  }
}
catch (Exception e) {
  // presumably, not relevant
}

That should not be needed on Android 4.4+, though with the exception handler in place, I would not expect any particular problem if you run it and, someday, they get rid of sHasPermanentMenuKey outright.

Personally, I still wouldn’t change things on Android 4.3 and below, as I suspect it’s a whack-a-mole situation, where you will replace complaints about having no menu with complaints about having duplicate versions of the same menu. That being said, since this is now the officially endorsed behavior going forward, I have no problems with developers aiming for consistency on older devices.

A hat tip to the commenter on the issue I filed regarding this, pointing out the change.

Leave a Comment