如何始终显示在动作条Android设置按钮? [英] How to always show Android settings button on ActionBar?

查看:123
本文介绍了如何始终显示在动作条Android设置按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何能始终显示在动作条Android设置按钮? (4.0 +)

How can I always show Android settings button on ActionBar? (4.0+)

我想告诉它,即使该设备有一个硬件按钮设置,所以它会带和不带硬件按钮的设备是一样的。

I would like to show it even if the device has an hardware button for settings, so it would be same with devices with and without hardware buttons.

这就是我所说的: http://oi48.tinypic.com/2j104l0.jpg

推荐答案

有一个可怕的黑客通常已回答了许多问题。调用此从您的onCreate()

There is one awful hack which generally have been answered on many questions. Call this from your onCreate():

private void getOverflowMenu() {

     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) {
        e.printStackTrace();
    }
}

强烈建议不要使用这个技巧为 sHasPermanentMenuKey 字段可以随时更改。然而,这一直是我和其他人uptil现在。请参见

It is highly suggested not to use this hack as sHasPermanentMenuKey field can change anytime. However this has been working for me and others uptil now. See

的Andr​​oid操作栏不显示溢出

在第二个音符,硬件按钮,在手机上present是有原因的。只是显示了另外溢出菜单可能会混淆用户。理想情况下,用户会非常习惯使用他/她的个人电话。因此,如果用户的电话有硬件按钮溢出菜单选项,那么它不必具有上的动作杆顶端的图标。具有加按钮可能会混淆用户由于不同的应用程序的行为差异。

On a second note, the hardware button is present on the phone for a reason. Just showing the addition overflow menu might confuse your users. Ideally a user would be very much accustomed to using his/her personal phone. So, if the user's phone has a hardware button for overflow menu option, then it need not have the icon on the top of action bar. Having an addition button might confuse users due to difference in behavior in different apps.

希望有所帮助。

编辑:

总之,它不建议作为 sHasPermanentMenuKey 字段在Android code可随时更改,如果没有找到,这将打破你的应用程序。

In short, its not recommended as sHasPermanentMenuKey field in the Android code can be changed anytime, which will break your app if not found.

这篇关于如何始终显示在动作条Android设置按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆