Optionsmenu is the menu option in the Android phone
First, to implement the menu operation is to first override the Oncreateoptionsmenu (Menu menu) method
There are usually two ways to implement the addition of options in a menu
The first is dynamic adding: Calling the Add method directly in the Oncreateoptionsmenu method
public boolean Oncreateoptionsmenu (Menu menu) { menu.add (1,100,1, "1"); Menu.add (1,101,1, "Menu 2"); Menu.add (1,102,1, "menu 3"); Menu.add (1,103,1, "menu 4"); Menu.add (1,104,1, "menu 5"); return true; }
The second is by means of an XML file
Start by creating a new XML file in the menu file under the Res folder (the default is no menu file under the Res folder in Android Studio, just create a new one yourself)
Then write out the layout to
<menu xmlns:android= "Http://schemas.android.com/apk/res/android" > <item android:id= "@+id/menu_ Item1 " android:orderincategory=" android:showasaction= " never" android:title= "menu One" ></item > <item android:id= "@+id/menu_item2" android:orderincategory= " android:showasaction=" "Never" android:title= "Menu II" ></item></menu>
At the same time, if you implement the menu option in an XML file, you will call this layout in the Oncreateoptionsmenu method
public boolean Oncreateoptionsmenu (Menu menu) { getmenuinflater (). Inflate (R.menu.main,menu); return true; }
The last is the menu listener method onoptionsitemselected (MenuItem Item)
@Override Public Boolean onoptionsitemselected (MenuItem item) { return super.onoptionsitemselected (item); }}
Simple app for menu Optionsmenu in Android