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.