Si8
Si8

Reputation: 9225

Add custom icon for inflated menu

I am trying to add icon to the menu (since it looks so boring)

enter image description here

My menu xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/action_about"
        android:orderInCategory="200"
        android:showAsAction="never"
        android:icon="@drawable/icon"
        android:title="About" />
    <item
        android:id="@+id/action_help"
        android:orderInCategory="200"
        android:showAsAction="never"
        android:icon="@drawable/help"
        android:title="Help" />
    <item
        android:id="@+id/action_rate"
        android:orderInCategory="300"
        android:showAsAction="never"
        android:title="Rate This App"
        android:icon="@drawable/star" />
    <item
        android:id="@+id/action_quit"
        android:orderInCategory="400"
        android:showAsAction="never"
        android:title="Quit"
        android:icon="@drawable/quit" />

</menu>

Part of the Java code:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);

    //Set icon for the menu button
    Drawable icon = getResources().getDrawable(R.drawable.icon);
    menu.getItem(0).setIcon(icon);

    return true;
}

I still don't see the icon on the menu. I am running my phone and the AVD 4.2+. Is it that Google took out icon support for menu?

Upvotes: 0

Views: 978

Answers (1)

Matt Robertson
Matt Robertson

Reputation: 3165

Hopefully this is a dumb question, but do you have the icon image in one of your drawable folders with the name you are using to access it?

If everything is set up correctly, try cleaning your project & running it again (making sure to build it as well).

Upvotes: 2

Related Questions