Learn to understand the Android menus menu Operation _android

Source: Internet
Author: User

Today, I saw the pro Android 3 menu in the chapter, the entire menu system of Android has a further understanding, so tidy up the notes and share with you.

PS: The Pro Android 3 is highly recommended, the best Android book I've seen so far, and the Chinese version of Android 2.

Understanding Android's Menu

Menus are an integral part of many applications, even more so in Android, where all mobile phones with Android have a "menu" key, which shows the specificity of the menu in the Android program. The Android SDK offers the following menus:

Options Menu: The most common menu, Android, is called Option Menu submenu: Android Click on the submenu will pop up the suspension window display submenu items. Submenus do not support nesting, which means no more submenus can be included in submenus. Context Menu: Android Long click the menu that appears after the view control, Windows right-click pop-up menu that is the context menu icon menu: This is relatively simple, is the menu item with icon, you need to note that submenu items, context menu items, extended menu items can not display the icon. Select the menu: the use of less, the introduction of alternative, this article first skipped, in fact, I have not yet figured out,

Extended menu: option Menu can only display 6 menu items, more than 6, the 6th menu item will be replaced by a system called "more" submenu, the original display menu items as the "More" menu submenu items. The following figure:

    

The 6th menu item automatically becomes "more"

                      

Click "More" to show other menu items

ANDROID3.0 also introduced a call action bar of things, this article does not explain, everyone Google.

The Android.view.Menu interface represents a menu that Android uses to manage various menu items. Note that we generally do not create menus ourselves, because each activity defaults to one, and what we do is add menu items to it and respond to the click events of the menu item. Android.view.MenuItem represents each menu item, and Android.view.SubMenu represents a submenu. The relationship between the three can be expressed in the following diagram

  

As mentioned above, each activity contains a menu, a menu can contain multiple menu items and multiple submenus, and a submenu is actually a menu (because it implements the menu interface), so submenus can also contain multiple menu items. submenu inherits the Addsubmenu () method of the menu, but a run-time error is thrown when invoked. Oncreateoptionsmenu () and onoptionsmenuselected () are the two callback methods available in the activity to create a menu item and a click to respond to a menu item.

The next "Android Menu action creation and Response menu" will show you how to use code to create menu items, group items, and various ways to respond to menu events.

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.