submenu of Android Menu submenu

Source: Internet
Author: User

A submenu is a menu that pops up when you click an option in the menu to select an action on the menu

His operation is similar to the previous two types of menu operation

Dynamically add

@Override Public    Boolean oncreateoptionsmenu (Menu menu) {        submenu file = Menu.addsubmenu ("files");        submenu edit = Menu.addsubmenu ("edit");        File.setheadertitle ("file");        File.setheadericon (r.mipmap.ic_launcher);        File.add (1,1,1, "new");        File.add (1,2,1, "open");        File.add (1,3,1, "save");        Edit.setheadertitle ("edit");        Edit.setheadericon (r.mipmap.ic_launcher);        Edit.add (2,1,1, "copy");        Edit.add (2,2,1, "paste");        Edit.add (2,3,1, "cut");        return true;    }

XML file Additions

@Override Public    Boolean oncreateoptionsmenu (Menu menu) {        submenu file = Menu.addsubmenu ("files");        submenu edit = Menu.addsubmenu ("edit");           Menuinflater inflater = Getmenuinflater ();        Inflater.inflate (r.menu.main,menu);        return true;    }

This layout file is a little different from the double-decker menu

<?xml version= "1.0" encoding= "Utf-8"? ><menu xmlns:android= "Http://schemas.android.com/apk/res/android" ><item android:id= "@+id/file" android:title= "file" > <menu> <item android:id= "@+id/fi           Le_new "android:orderincategory=" android:title= "new" > </item> <item Android:id= "@+id/file_open" android:orderincategory= "android:title=" "Open" > & lt;/item> <item android:id= "@+id/file_s" android:orderincategory= "[Android:t]"        itle= "Save" > </item> </menu></item> <item android:id= "@+id/edit"                android:title= "edit" > <menu> <item android:id= "@+id/edit_c"            android:orderincategory= "android:title=" "Copy" > </item> <item android:Id= "@+id/edit_v" android:orderincategory= "android:title=" > "Paste" </item> <item android:id= "@+id/edit_x" android:orderincategory= "100 "Android:title=" Cut > </item> </menu> </item>< /menu>

submenu of Android Menu submenu

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.