简体   繁体   English

带三个点的ActionBar溢出菜单未显示

[英]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. 我的设备在android:4.1.2上运行,并且具有物理硬件菜单按钮。

I am adding 5 items to menu, when i set ShowAsAction ="never", the options menu is showing upon pressing physical hardware menu button. 我在菜单中添加了5个项目,当我将ShowAsAction设置为“ never”时,按下物理硬件菜单按钮即会显示选项菜单。 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 按照Commonsware描述这里

  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. 这在Android 4.4+上不需要,尽管有了异常处理程序,但我希望运行它不会遇到任何特殊问题,总有一天,他们会彻底摆脱sHasPermanentMenuKey

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. 就我个人而言,我仍然不会在Android 4.3及更低版本上进行任何更改,因为我怀疑这是一种令人讨厌的情况,在这种情况下,您将以关于相同菜单的重复版本的投诉代替无菜单的投诉。 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. 在我就此提出的问题上评论者一个提示,指出了更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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