Search code examples
androidactionbarsherlockandroid-actionbar-compat

ActionbarCompat not showing Action-Icons


When using ActionbarCompat as Actionbar BackPort I am having the problem that action-icons do not show up - same code/res works with actionbarsherlock.

Am I doing something wrong or is this not yet supported? I am also missing the whole Menu/MenuItem getSupportMenuInflater() part that ABS has in ActionBar compat - can anyone shed some light on this?


Solution

  • This question was already answered in Actionbar not shown with AppCompat.

    Add the following namespace to the "menu" item in your xml file

    xmlns:compat="http://schemas.android.com/apk/res-auto" 
    

    Then change the "showAsAction" attribute to use the new namespace

    compat:showAsAction="ifRoom"
    

    Here's a full example with one item in the menu, with the changes on lines 2 and 6 (from Actionbar not shown with AppCompat)

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