【问题标题】:Action item always appears in the overflow menu操作项始终出现在溢出菜单中
【发布时间】:2016-09-10 07:10:19
【问题描述】:

我正在使用 v7 支持库并在 menu_main.xml 文件中使用 app 命名空间。即使这样,操作也不会显示在操作栏中,而是显示在溢出栏中。即使我使用app:showAsAction="always"

,也会发生这种情况

menu_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      tools:context=".MainActivity">

    <item android:id="@+id/action_settings"
          android:title="@string/action_settings"
          android:orderInCategory="100"
          app:showAsAction="never"/>

    <item android:id="@+id/action_create_order"
        android:title="@string/action_create_order"
        android:orderInCategory="1"
        app:showAsAction="always"
        android:icon="@drawable/add_box_black_icon"
        />
</menu>

【问题讨论】:

    标签: android xml android-actionbar


    【解决方案1】:

    项目的顺序很重要 - 如果您想实现您的原始想法,请交换创建顺序和设置。

    【讨论】:

    • @KaushikS 你会在任何地方增加你的菜单,还是只使用这里指定的context
    • 我在onCreateOptionsMenu中充气
    • @KaushikS 是的,你应该 - 也许也添加这个方法,只是为了验证它。另外,我通常不添加context 属性,也从未遇到过这样的问题。也许试试没有..
    猜你喜欢
    • 2014-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多