Using XML to define the menu
The menu resource file must be placed in the Res/menu directory. The menu resource file must use the <menu> tag as the root node. In addition to the <menu> tags, there are two other tabs for setting menu items and grouping, both <item> and <group>
<menu> does not have any attributes, but can be checked in the <item> tab, representing the form of a submenu, but the <item> tag can no longer be nested <item> tags
The properties of the 1.<item> tag have the following meanings:
ID: The resource ID that represents the menu item
Icon: Menu item icon resource ID
showasaction: There are five attributes: Ifroom, never, always, Withtext, Collapseactionview
Ifroom: It will appear in item, but it will be hidden in the overflow list if it already has 4 of an item. Of course, the number is not only limited to four, including the width of the screen.
Never: Never show. Only appears in the overflow list, and only the title is displayed, so it's best to take the title with you when you define the item
Always: Whether or not it appears
Withtext: motioned Actionbar to display the caption of the text. Actionbar will display this title as much as possible, but if the icon is valid and is limited by the Actionbar space, the text caption may appear incomplete
Collapseactionview: Declares that this operation window should be collapsed into a button, when the user selects this button, the Operation window expands. Otherwise, this operation window is visible in the default case, and even when used in the non-applicable, but also to combat the effective space of the action bar, generally to cooperate with ifroom in order to effectively
Just like home at menu, call the above XML file in the activity's Oncreateoptionsmenu method:
Getmenuinflater (). Inflate (r.menu.options, menu);
Searchview Searchview = (searchview) menu.finditem (R.id.menu_search)
. Getactionview ();
Basic usage of Android menu