【问题标题】:Action Bar doesn't appear on galaxy S3Galaxy S3 上不显示操作栏
【发布时间】:2014-07-20 23:08:23
【问题描述】:

我参加了android developers 培训并 编写了应该有操作栏的应用程序。

我在操作栏中添加了两个项目:

  • 第一个有icon和android:showAsAction="IfRoom"
  • 第二个,只有字符串和 android:showAsAction="Never"。

main_menu_actions.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.shaniandroid.myfirstapp.MainActivity" >

<!-- Search, should appear as action button -->
<item android:id="@+id/action_search"
      android:icon="@drawable/search_icon"
      android:title="@string/action_search"
      android:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_settings"
      android:title="@string/action_settings"
      android:showAsAction="never" />

但是没有显示操作栏!

这些项目仅在菜单按钮时显示 被按下。

我在之前的答案中读到“溢出”按钮没有出现 如果存在硬件菜单按钮,则在 4.3 上 - 这对于第二项是可以的。

但是第一项呢?它的图标不应该出现在屏幕顶部吗?

注意:我在 Galaxy S3 4.3 上运行该应用程序。

【问题讨论】:

    标签: android android-actionbar galaxy


    【解决方案1】:

    如果您使用的是 AppCompat,那么您应该使用您已声明的 showAsAction 命名空间 app。您的 main_menu_actions.xml 应如下所示:

    <menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.shaniandroid.myfirstapp.MainActivity" >
    
    <!-- Search, should appear as action button -->
    <item android:id="@+id/action_search"
          android:icon="@drawable/search_icon"
          android:title="@string/action_search"
          app:showAsAction="ifRoom" /> <!--here-->
    <!-- Settings, should always be in the overflow -->
    <item android:id="@+id/action_settings"
          android:title="@string/action_settings"
          app:showAsAction="never" /> <!--and here-->
    

    【讨论】:

    • 哦,谢谢你,没有意识到这一点。我会检查这个。问:有什么更好的办法 - 使用 AppCompat 还是不使用?我认为没有太多理由支持低于 4.x 的版本。
    • @shani 如果您不想支持前 ICS 设备,请使用本机 ActionBar。
    • “使用原生Action Bar”是否意味着根本不使用AppCompat?
    • AppCompat 是兼容库,允许您在 ICS(实际上是 Honeycomb)之前的 Android 版本上添加 ActionBar。因此,如果您的目标是 ICS 或更高版本,那么您根本不需要 AppCompat。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多