Adding icon to the menu item in Android

There is a good practice to add icons to the menu items.
I am going to show code snippet which add icon to the menu item:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
   menu.add(0, ADD_MENU_ITEM, 0, "Add").setIcon(android.R.drawable.ic_menu_add);
   return super.onCreateOptionsMenu(menu);
}

This code adds icon add to the menu item ADD_MENU_ITEM.

As you can see it is simple operation.

  • Share/Bookmark

Related posts:

  1. Adding alphabetical shortcut to the menu item in Android
  2. Loading Menus through XML files in Android
  3. Creating Options Menu and adding menu items to the Options Menu in Android
  4. Handling Options Menu item selections in Android
  5. Using Submenu in Android

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>