How to Create Android Menus
In android application menu is one of the important user interface entity which provides some action options for a particular view. In this tutorial i am discussing about creating android menus.
The final output of menu tutorial will be like below image
In this tutorial we are creating a simple menu with 6 menu items. On clicking on single menu item a simple Toast message will be shown.
1. Create a new project File ⇒ New ⇒ Android Project and give activity name asAndroidMenusActivity.
2. Now create an XML file under res/layout folder and name it as menu.xml.
3. Open menu.xml file and type following code. In the following code we are creating a single menu with 6 menu items. Each menu item has an icon and title for display the label under menu icon. Also we have id for each menu item to identify uniquely.
4. Now open your main Activity class file (AndroidMenusActivity.java) and type following code. In the following code each menu item is identified by its ID in switch case statement.
5. Finally run your project by right clicking on your project folder ⇒ Run As ⇒ 1 Android Application to test your application. On Android Emulator click on Menu Button to launch menu.