Android menu trace

Source: Internet
Author: User

Recently, I am very busy. I have been busy with projects of the Hangzhou Power Bureau and the wuxijiang hydropower plant, so I haven't updated my blog for a long time.

Play android in the evening and find it interesting to develop Android menus. Log on to the blog:

 
@ Override
 
PublicBoolean oncreateoptionsmenu (Android. View. menu ){
 
Menu. Add (0, 1, 0,"Start");
 
Menu. Add (0, 2, 0,"Cancel");
 
// Android. View. menu file = menu. addsubmenu (0, about, 0, "About Us ");
 
Submenu file = menu. addsubmenu (0, 3, 0,"About Us");
 
Menuinflater Inflater = getmenuinflater ();
 
Inflater. Inflate (R. Menu. Menu, file );
 
// Todo auto-generated method stub
Return True;
 
}

First, you need to rewrite the oncreateoptionsmenu method, that is, after the rewriting, the menu that comes with the mobile phone will appear according to your ideas ...... It's the same as not saying it.

The. Menu. Add (, 0, "START") that needs to be recorded here. The parameter meaning can be viewed directly.CodePrompt. The second parameter indicates the Itemid, which is unique. Because you need to obtain the menu

It must be used. Menu. Add adds a normal menu item.

The menu. addsubmenu below adds a special menu item, which has a sub menu item. This method returns a submenu object, because the submenu interface inherits

So it is okay to declare it as menu. Such as the line commented out in the Code.

The following describes how to load sub-menu items through an XML file. R. Menu. Menu is a file named menu. xml under the Res/menu directory. It contains sub-menu items.

Okay. One o'clock again.

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.