【问题标题】:How to add menu button on the navigation bar如何在导航栏上添加菜单按钮
【发布时间】:2013-10-26 08:00:48
【问题描述】:

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

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

值文件夹中的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>

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

这段代码运行良好,但如果我没有任何操作栏,我想将菜单按钮放在导航栏中。

我为此做了很多谷歌搜索,但找不到任何可行的解决方案。

提前致谢。

【问题讨论】:

    标签: android android-actionbar navigationbar


    【解决方案1】:

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

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

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

            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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多