简体   繁体   中英

ActionBar Menu icons only shows on overflow menu

I am currently having an issue showing the option menu items on the actionbar. For some reason, the items only show on the overflow menu and this is true for post ICS devices as well. I am using the v7-appcompat library to support sdks from version 8 onwards.

In the main activity I have:

@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;
}

My menu items are defined as follow:

<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"/>

I also have a spinner in the actionbar with the following xml layout:

<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" />

I can't seem to get my head around it.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM