我有一个简单的应用程序,只需要带有一些选项的菜单按钮,它就可以在所有设备上使用。

无论如何,我的应用程序在所有情况下都可以正常运行,除了无法将菜单按钮放在导航栏上。
这是我的代码:

值文件夹中的styles.xml

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:windowNoTitle">true</item>
</style>

value-v11和value-v14文件夹中的styles.xml
<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:windowNoTitle">false</item>
    <item name="android:windowActionBar">true</item>
    <item name="android:actionBarStyle">@android:style/Widget.Holo.ActionBar</item>
</style>

此代码出现在我 Activity 的所有onCreate事件中
if(Build.VERSION.SDK_INT <= 10 || (Build.VERSION.SDK_INT >= 14 &&
ViewConfiguration.get(this).hasPermanentMenuKey()))
{
// menu key is present
ActionBar actionBar = getActionBar();
if(actionBar!=null)
actionBar.hide();
}
else
{
//No menu key
    ActionBar actionBar = getActionBar();
    if(actionBar!=null)
actionBar.show();
}

这段代码可以正常工作,但是如果我没有任何操作栏,我想将菜单按钮放在导航栏中。

为此,我做了很多事情,但是我找不到任何可行的解决方案。

提前致谢。

最佳答案

由于没有人回答我的问题,所以我必须自己回答。

首先,似乎不建议激活导航栏中的菜单按钮! (由Google提供)

无论如何,如果您有兴趣激活它,那么您要做的就是:

        1. Make a simple menu like before
        2. Not to use an action bar
        3. Set targetSdkVersion to 13 or below

并且,强烈建议阅读这篇文章Say Goodbye To The Menu Button

关于android - 如何在导航栏上添加菜单按钮,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19604396/

10-11 07:02