0

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?

Si8
  • 9,141
  • 22
  • 109
  • 221

1 Answers1

2

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

Matt Robertson
  • 2,928
  • 5
  • 34
  • 62
  • No question is ever dumb but to answer it, yes they are all in the drawable folder and I did clean my project more than once but still nothing :/ – Si8 Nov 08 '13 at 15:51
  • Try adding super.onCreateOptionsMenu(menu) as the first line in your onCreateOptionsMenu(menu) function. – Matt Robertson Nov 08 '13 at 15:53
  • Why are you trying to set the icon programatically? Since you have the icon reference in the menu xml, you don't have to set it in your java code. It may even be messing it up for some reason... – Matt Robertson Nov 08 '13 at 15:57
  • Commented it out but still nothing. – Si8 Nov 08 '13 at 15:58
  • Hmm.. Do you have access to an Android phone you could debug on? There's always the chance that your code works (looks like it should to me) but the emulator is just being a teenage girl. – Matt Robertson Nov 08 '13 at 16:00
  • Check out the accepted answer from this link and see if it works for you. http://stackoverflow.com/questions/8908985/android-options-menu-icon-wont-display – Matt Robertson Nov 08 '13 at 16:06
  • You know what I just read it too. I guess I will include the icon and it will work on the older versions. Thanks for the help :) – Si8 Nov 08 '13 at 16:07