Basic usage of Android menu

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.