android implements the method that always displays the overflow menu

  • 2020-06-01 10:59:00
  • OfStack

In Android programming, it is usually shown as a menu of three vertical dots when there are too many items in Actionbar, but it is not shown in real machine testing. After searching for information and testing, the problem is found: if the machine has the menu key of entity, the overflow menu is not displayed on the right side, but is generated by pressing menu instead. This is not conducive to unified 1 interface style.

We can change the display of this by changing the presence or absence of the entity menu key that the system detects.

The menu display is based on the public boolean hasPermanentMenuKey () method. This method is to get the boolean value of sHasPermanentMenuKey.

The solution is as follows:

Add in onCreate() :

try {
ViewConfiguration mconfig = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if(menuKeyField != null) {
menuKeyField.setBoolean(mconfig, false);
} catch (Exception ex) {

Related articles: