如何在导航栏上添加菜单按钮

时间:2013-10-26 08:00:49

标签: android android-actionbar navigationbar

我有一个简单的应用程序,只需要一个带有一些选项的菜单按钮,它应该适用于所有设备。

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

值文件夹中的styles.xml

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:windowNoTitle">true</item>        
</style>
值p11&amp;中的

styles.xml value-v14文件夹

<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>

此代码出现在我的活动的所有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();
}

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

我已经做了很多谷歌搜索,但我找不到任何有效的解决方案。

先谢谢。

1 个答案:

答案 0 :(得分:12)

由于没有人回答我的问题,我不得不自己回答。

首先,似乎不建议激活导航栏中的菜单按钮! (谷歌)

无论如何,如果你有兴趣激活它,你所要做的就是:

        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