How to get Android ActionBar menu item icons to show (without compatibility libraries)

I recently upgraded an Android application I’m working on to get away from all of the “application compatibility” stuff and only use Java classes that are not in the compatibility libraries. When I did this, all of my menu item icons disappeared from the action bars, and they appeared only as text in the overflow menus. Not cool.

In short, to fix this problem I just had to add this setting to my menu item definitions:

android:showAsAction="ifRoom"

For example, I have one menu defined in an XML file named res/menu/menu_main.xml, and its source code looks like this:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- used to need this custom namespace with 'app compatibility' libraries -->
    <!--xmlns:myapp="http://schemas.android.com/apk/res-auto">-->

    <!-- from the docs: to request that an item appear directly in the action bar as an action button, include showAsAction="ifRoom" -->
    <!-- menu resources: http://developer.android.com/guide/topics/resources/menu-resource.html -->
    
    <!-- add quote -->
    <item android:id="@+id/menu_item_new_quote"
          android:icon="@android:drawable/ic_menu_add"
          android:title="@string/menu_new_quote"
          android:showAsAction="ifRoom"/>

    <!-- prefs -->
    <item android:id="@+id/menu_item_prefs"
          android:icon="@android:drawable/ic_menu_manage"
          android:title="@string/menu_prefs"
          android:showAsAction="ifRoom" />

</menu>

As you can guess from one of the comments, I used to use this approach:

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

      .
      .
      .

    <item android:id="@+id/menu_item_new_quote"
          android:icon="@android:drawable/ic_menu_add"
          android:title="@string/menu_new_quote"
          myapp:showAsAction="ifRoom"/>

but this approach IS NOT NEEDED unless you’re using the Android compatibility libraries. Once I got all of the application compatibility libraries out of my Java code and switched to this setting:

android:showAsAction="ifRoom"

my menu items got out of the overflow menu and again appeared as icons in each ActionBar.