Icons and MenuItem for Android
I’ve been working through Ed Burnette’s book, “Hello, Andorid” and it’s given me a number of new tricks already; I’m only about a quarter of the way through. One of the changes I made for my Android game Jumpy was to move the programmatic building of the menu to a menu.xml file instead, as Mr. Burnette describes in Chapter 3 of his book.
One thing that the book does not mention is adding an icon to the menu item. With a little investigation I found the android:icon element which allows you to point to a drawable. I went a little further and found Google’s default setting icon by using the drawable “@android:drawable/ic_menu_preferences”.
One of my menu items in the menu.xml file now looks like,
<item android:id="@+id/settings_menu_item" android:title="@string/settings_menu_label" android:alphabeticShortcut="@string/settings_menu_shortcut" android:icon="@android:drawable/ic_menu_preferences" />
So now my menu item for “Settings” now looks like the following.
![]() |
With a little more hunting I found the list of MenuItem elements and my new favorite Android API page, the android.R.styleable class. It’s got a whole bunch of info on all the attributes and element names allowed in the Android XML files, from MenuItem to AndroidManifestPermission, I highly recommend you take a gander at it to learn all sorts of interesting tidbits.
I also recommend Ed Burnette’s book for more info on the menu.xml file and a whole host of other topics for developing Android programs.


June 30th, 2010 at 11:03 am
Hey, I’d recommend you make a screenshot blog post of all the android.R.drawable’s