Android appcompat actionbar menu item showAsAction not working

pickle_inspector picture pickle_inspector · Feb 19, 2014 · Viewed 27.9k times · Source

I have a menu item that is showing up on android 4.x but not on 2.x. Here is my 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/menu_filter"
    android:title="Filter"
    app:showAsAction="always"/>  
</menu>

This is my actionbar style

<style name="style1_actionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
    <item name="android:background">@color/blue_dark</item>
    <item name="android:textColor">@color/white</item>
    <item name="actionMenuTextAppearance">@color/white</item>
    <item name="background">@color/blue_dark</item>
</style>

Any ideas?

Edit: removed double quote typo

Could it be the fact that I am showing only text, no icons? I'm kind of stuck here.

Answer

pickle_inspector picture pickle_inspector · Feb 19, 2014

Whew, thanks for your help guys but I managed to figure it out. It wasn't a problem with the xml, it was a problem with the onCreateOptionsMenu function.

I was using this

new MenuInflater(getApplication()).inflate(R.menu.activity_wentry_editor, menu); 

instead of this

MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_wentry_editor, menu);

Not entirely sure why this works but it does.