【问题标题】:Actionbar not shown with AppCompatAppCompat 未显示操作栏
【发布时间】:2013-08-29 11:57:05
【问题描述】:

我正在使用 AppCompat 将我的应用程序反向移植到 API7,但操作栏出现问题。

当我使用 FragmentActivity 时,操作栏会显示在我的手机上 (API18),但使用 ActionBarActivity 时,它会通过按菜单按钮显示为选项菜单。

在使用 API7 的模拟器上,操作栏始终显示为选项菜单。

有什么想法吗?

【问题讨论】:

    标签: android android-actionbar android-actionbar-compat android-appcompat


    【解决方案1】:

    为您的菜单项使用兼容名称空间,如下所示:

    <menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:compat="http://schemas.android.com/apk/res-auto" >
        <item android:id="@+id/action_whatever"
          android:icon="@drawable/ic_action_whatever"
          android:title="@string/whatever"
          compat:showAsAction="ifRoom"  />
    </menu>
    

    【讨论】:

      【解决方案2】:

      a duplicate that points to this post 相关,尽管将showAsAction 设置为always,但我无法让我的按钮显示为操作项而不是溢出项。我设法通过使用Activity 而不是ActionBarActivity 扩展我的活动来强制它。根据this answer,如果你不需要支持11以下的api级别,这是可以接受的。

      ...extends ActionBarActivity:

      ...extends Activity:

      【讨论】:

        【解决方案3】:

        我使用 Doogee Valencia Y100Pro 进行调试,菜单“三个小方块”不可见,但是当我使用 android.support.v7.app.ActionBarActivity 扩展 MainActivity 时,我在操作栏中获得文本/图标菜单。接下来screenshot和menu.xml

        <?xml version="1.0" encoding="utf-8"?>
        <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
            <item
                android:id="@+id/action_update"
                android:icon="@drawable/ic_refresh"
                android:title="@string/action_update"
                app:showAsAction="always"/>
            <item android:id="@+id/action_settings"
                android:title="@string/action_settings"
                app:showAsAction="ifRoom"/>
        </menu>
        

        【讨论】:

          猜你喜欢
          • 2015-01-14
          • 1970-01-01
          • 2013-08-02
          • 2015-04-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-12-15
          相关资源
          最近更新 更多