【问题标题】:ActionBar to show icons, but it shows the menu commands instead [duplicate]ActionBar 显示图标,但它显示菜单命令而不是[重复]
【发布时间】:2013-12-25 17:51:11
【问题描述】:

我有一个带有一些选项卡的操作栏(来自 support.v7),到目前为止一切都很好。

问题出在菜单上。

 <menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:name="http://schemas.android.com/apk/res-auto"
    >

   <item
        android:id="@+id/action_m1"
         android:orderInCategory="100"
        android:showAsAction="always"
        android:icon="@drawable/ic_action_chat"
        android:title=""/>



    <item
        android:id="@+id/action_m2"
        android:orderInCategory="101"
        android:showAsAction="always"
        android:icon="@drawable/ic_action_merge"
        android:title="">
    </item>

</menu>

“总是”被忽略。它从不显示为动作,仅当我按下“菜单”时才显示。即使我没有加载任何选项卡,并且有足够的空间,也会发生这种情况。

可能出了什么问题,我错过了 ActionBar 上的一些调用吗?

最好的问候。

【问题讨论】:

  • tltle 似乎是空的,你尝试了一些标题吗?但我不确定

标签: android android-actionbar


【解决方案1】:

在使用支持库ActionBar 时,您不能为菜单项使用 android 命名空间。相反,您需要在属性前面加上您的自定义命名空间:

// in the menu xml file
xmlns:name="http://schemas.android.com/apk/res-auto"

<item
    android:id="@+id/action_m1"
    android:orderInCategory="100"
    name:showAsAction="always"
    android:icon="@drawable/ic_action_chat"
    android:title=""/>

您可以在official guide阅读更多内容。

【讨论】:

  • 还是同样的问题。
  • @Michael 你真的使用新的命名空间吗?在我的示例中,我有 name:showAsAction="always"
  • 是的,我刚刚注意到了...谢谢 :)
  • 想想如果你的手机或模拟器中有官方菜单按钮,它会影响操作栏菜单。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多