Introduction to Android Menu

Source: Internet
Author: User

There are three kinds of menus on Android:

Options menu (Optionmenu),

Context menu (ContextMenu),

submenu (submenu).

A common option menu is when you click the menu button to display it at the bottom of the corresponding activity.

Note: Each activity is associated with one and only one menu object.

In the activity

public boolean Oncreateoptionmenu (Menu menu)// Initialize menu, return True to show that Menu,false does not display

public boolean onoptionsitemselected (MenuItem Item)//is called when the menu item is clicked

Here is a simple demo

1  <?XML version= "1.0" encoding= "Utf-8"?>2  <Menuxmlns:android= "Http://schemas.android.com/apk/res/android">3       <ItemAndroid:id= "@+id/menu_setting" 4 Android:title= "Settings"5 Android:icon= "@drawable/setting">6      </Item>7  </Menu>
1  Public Booleanonoptionsitemselected (MenuItem item) {2     Switch(Item.getitemid ()//get the Itemid of the item clicked3         {4              CaseMenu.first:5               ......6                   Break; 7              CaseMenu.first+1:8                  ......9                   Break; Ten             default: One             //to the parent class to handle events that are not handled A              return Super. onoptionsitemselected (item); -          } -       //returns true to indicate that the event of the menu item has been processed, and that the event does not need to be propagated anymore. the         return true; -  -}

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.