【问题标题】:ActionBar Menu icons only shows on overflow menuActionBar 菜单图标仅显示在溢出菜单上
【发布时间】:2014-01-24 16:36:48
【问题描述】:

我目前在操作栏上显示选项菜单项时遇到问题。出于某种原因,这些项目仅显示在溢出菜单上,对于后 ICS 设备也是如此。我正在使用 v7-appcompat 库从版本 8 开始支持 sdks。

在我的主要活动中:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.wild_news, menu);
    return true;
}

我的菜单项定义如下:

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

  <item
    android:id="@+id/menu_refresh"
    android:icon="@drawable/ic_action_refresh"
    **app:showAsAction="always"**
    android:title="@string/menuTitle_refresh"/>
<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    **app:showAsAction="ifRoom"**
    android:title="@string/action_settings"/>

我在操作栏中也有一个微调器,其 xml 布局如下:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:minHeight="50dp"
       android:minWidth="140dp"
       android:layout_gravity="center_vertical"
       style="@style/ActionBarNavListTitle" />

我似乎无法理解它。

【问题讨论】:

  • 我不清楚 Spinner 和/或 TextView 的放置位置。你能展示你是如何将它们添加到你的操作栏中的吗?您的活动是否扩展了 ActionBarActivity?
  • 嗨,保罗,是的,我正在使用 ActionBarActivity 扩展。我使用标准的 ActionBar 将导航模式设置为列表,然后基于此实例化适配器。但我发现问题更多在于样式方面。

标签: android android-layout android-actionbar android-menu android-appcompat


【解决方案1】:

很好,我发现问题与我现在已解决的 ActionBar 样式定义不匹配有关:

<style name="ActionBarStyle"   parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-29
    • 1970-01-01
    • 2013-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多