Android menu details (1) -- Understanding the menu in Android

Source: Internet
Author: User
Preface

Today, I read the menu in pro Android 3 and have a better understanding of the entire menu system of Android. So I will take some notes to share with you.

PS: strongly recommendedPro Android 3It is the best Android book I have seen so far. The Chinese version is published in "proficient in Android 2".

Understand Android menus

Menus are an indispensable part of many apps, especially in Android. All mobile phones carrying Android systems even have a "menu" key. This shows the special nature of menus in Android apps. The android SDK provides the following menus:

  1. Option menu: The most common menu. It is called option menu in Android.
  2. Sub-menu: Click sub-menu in Android to display sub-menu items in the floating window.Sub-menus do not support nestingThat is, other sub-menus cannot be included in the sub-menu.
  3. Context Menu: In AndroidLong pressRight-click the menu that appears after the view control, and the context menu is displayed in windows.
  4. Icon menu: this is a simple menu item with an icon. Note thatIcons cannot be displayed for sub-menu items, context menu items, and extended menu items..
  5. Select menu (alternative menu ~~)
  6. Extended menu: up to six menu items can be displayed in the option menu. If more than six menu items are displayed, the system replaces 6th menu items with a sub menu named "more, all menu items that cannot be displayed are used as sub-menu items of the "more" menu. For example:

The 6th menu items are automatically changed to "more". Click "more" to display other menu items.

Android3.0 introduces another item called action bar. This article will not explain it. You can Google it yourself.

The android. View. menu interface represents a menu. Android uses it to manage various menu items. Note that we generally do not create menus by ourselves, because each activity comes with one by default,What we need to do is add a menu item for it and respond to the Click Event of the menu item.. Android. View. menuitem indicates each menu item, and Android. View. submenu indicates the sub menu. The relationship between the three can be used to represent

  

As mentioned above, each activity contains one menu, and one menu can contain multiple menu items and multiple sub-menus. The sub-menu is actually a menu (because it implements the menu interface ), therefore, a sub-menu can contain multiple menu items. Submenu inherits the addsubmenu () method of menu, but a runtime error is thrown during the call. Oncreateoptionsmenu () and onoptionsmenuselected () are two callback methods provided in the activity for creating menu items and clicking the response menu items.

The next Android menu description (II)-create and respond to menu describes how to use code to create menu items, group menu items, and various methods 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.