简体   繁体   中英

ActionBar overflow menu with three dots is not showing

My device is running on android:4.1.2 and is having physical hardware menu button.

I am adding 5 items to menu, when i set ShowAsAction ="never", the options menu is showing upon pressing physical hardware menu button. Is there any way to show them on the action bar with overflow menu(i mean with three dots which can be seen for the devices which doesn't have physical hardware menu button) for the devices which are having physical hardware menu button

As per Commonsware described here

  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM