Android Menu, androidmenu
Android Menu creation requires the following packages:
Import android. view. Menu; import android. view. MenuItem; import android. widget. Toast; // The package name required by Toast.
PS: the simple method to search for registration is to hover your mouse over the data type of the required package, and then you will see the required package name in the eclipse prompt box.
You need to create a menu folder under your res folder (PS: I personally think that the name is only a code, as personal preferences, of course, if it is developed by a person) and then load an Android XML file under the folder
Then you can write items happily in it. The following is an example.
<? Xml version = "1.0" encoding = "UTF-8"?> <Menu xmlns: android = "http://schemas.android.com/apk/res/android"> <item android: id = "@ + id/one" android: title = "first_title_name"/> <item android: id = "@ + id/two" android: title = "second_title_name"/> // you can create many other options. </men>
Next you need to load your menu in your Activity
@ Override public boolean onCreatOptionsMenu (Menu menu) {getMenuInflater (). inflate (R. menu. main, menu); // main is the name of the XML file you wrote in the menu (you can also choose another one ), in my understanding, the menu is to pass all the parameters into the menu object and return true;} @ Override public boolean onOptionsItemSelected (MenuItem item) {switch (item. getItemId () {// This method of obtaining the id has to be spjected, and it seems very bad case R. id. one: Toast. makeText (this, "the words you want to say", Toast. LENGTH_SHORT ). show (); // In the written item, I choose to display a Toast break after I click it; case R. id. two: Toast. makeText (this, "the words you want to say", Toast. LENGTH_LONG ). show (); break; default:} return true ;}