There are three kinds of menus on Android:
Options menu (Optionmenu),
Context menu (ContextMenu),
submenu (submenu).
A common option menu is when you click the menu button to display it at the bottom of the corresponding activity.
Note: Each activity is associated with one and only one menu object.
In the activity
public boolean Oncreateoptionmenu (Menu menu)// Initialize menu, return True to show that Menu,false does not display
public boolean onoptionsitemselected (MenuItem Item)//is called when the menu item is clicked
Here is a simple demo
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Menuxmlns:android= "Http://schemas.android.com/apk/res/android">3 <ItemAndroid:id= "@+id/menu_setting" 4 Android:title= "Settings"5 Android:icon= "@drawable/setting">6 </Item>7 </Menu>
1 Public Booleanonoptionsitemselected (MenuItem item) {2 Switch(Item.getitemid ()//get the Itemid of the item clicked3 {4 CaseMenu.first:5 ......6 Break; 7 CaseMenu.first+1:8 ......9 Break; Ten default: One //to the parent class to handle events that are not handled A return Super. onoptionsitemselected (item); - } - //returns true to indicate that the event of the menu item has been processed, and that the event does not need to be propagated anymore. the return true; - -}