强制显示ActionBar上的菜单按钮

作者: zhangyugehu | 来源:发表于2016-08-17 15:22 被阅读68次

原文地址

Android系统会检测系统是否存在实体** 菜单** 按键,如果存在会隐藏Actionbar上的菜单按钮,反之。
我们可以反射系统的 ***ViewConfiguration ***类去修改 sHasPermanentMenuKey 这个值,强制修改它的显示状态。

private void setOverflowShowingAlways() {  
        try {  
            ViewConfiguration config = ViewConfiguration.get(this);  
            Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");  
            menuKeyField.setAccessible(true);  
            menuKeyField.setBoolean(config, false);  
        } catch (Exception e) {  
        }  
    }

然后在OnCreate中调用即可

使用前:

qian.png

使用后:

hou.png

相关文章

网友评论

    本文标题:强制显示ActionBar上的菜单按钮

    本文链接:https://www.haomeiwen.com/subject/ozmmsttx.html