Android menu details 4: Sub menu

Source: Internet
Author: User
Create submenus

A sub-menu is a menu opened on an existing menu. You can add sub-menus to any menu.ProgramSub-menus are the best choice if they have many functions and can be organized by category, such as the menu bar (file, edit, view, and so on) in a PC program .).

When creating your menu resource, you can add<Menu>Element as<Item>To create a sub-menu. For example:

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <menu xmlns: Android = "http://schemas.android.com/apk/res/android"> <br/> <item Android: Id = "@ + ID/file" <br/> Android: icon = "@ drawable/file" <br/> Android: Title = "@ string/file"> <br/> <! -- "File" submenu --> <br/> <menu> <br/> <item Android: Id = "@ + ID/create_new" <br/> Android: title = "@ string/create_new"/> <br/> <item Android: Id = "@ + ID/Open" <br/> Android: title = "@ string/Open"/> <br/> </menu> <br/> </item> <br/> </menu>

When you select a menu item from the sub-menu, the callback method selected by the response menu item of the parent menu will receive the event. For example, if the above menu is an option menu, the methodOnoptionsitemselected ()It will be called.

you can also use addsubmenu () to dynamically Add sub-menus to a menu. this method returns a New submenu object. You can use the add () method to add menu items to this submenu object.

Related Article

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.