Search code examples
androidandroid-actionbarandroid-actionbar-compatandroid-actionbaractivity

Android: Icons don't appear in Action Bar


I'm following the google tutorial for action bars but the icons don't appear on it, this is the menu xml file:

<menu   xmlns:android="http://schemas.android.com/apk/res/android" 
        xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
    <item android:id="@+id/action_refresh"
          android:icon="@drawable/ic_action_refresh"
          android:title="refresh"
          android:showAsAction="ifRoom"/>
    <item android:id="@+id/action_settings"
          android:icon="@drawable/ic_action_settings"
          android:title="settings"
          android:showAsAction="ifRoom"/>
     <item android:id="@+id/action_compose"
          android:icon="@drawable/ic_action_new"
          android:title="add"
          android:showAsAction="ifRoom"/>
</menu>

and this in my main acivity:

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu items for use in the action bar
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main_activity_bar, menu);
        return super.onCreateOptionsMenu(menu);
    }

Solution

  • Use yourapp:showAsAction instead of android:showAsAction
    And make sure your Activity extends ActionBarActivity from the compat lib