Login     Sign Up
Tugadar (@admin)
21 days ago
20 Views

Menus offer a way to expose application functions without sacrificing valuable screen space. Each Activity can specify its own Activity menu that’s displayed when the device’s menu button is pressed.

Android also supports context menus that can be assigned to any View within an Activity. A View’s context menu is triggered when a user holds the middle D-pad button, depresses the trackball, or long-presses the touch screen for around 3 seconds when the View has focus.

Activity and context menus support submenus, checkboxes, radio buttons, shortcut keys, and icons.

Introducing the Android Menu System

If you’ve ever tried to navigate a mobile phone menu system using a stylus or trackball, you’ll know that traditional menu systems are awkward to use on mobile devices.

To improve the usability of application menus, Android features a three-stage menu system optimized for small screens:

❑The Icon Menu This compact menu (shown in Figure 4-4) appears along the bottom of the screen when the Menu button is pressed. It displays the icons and text for up to six Menu Items (or submenus).

This icon menu does not display checkboxes, radio buttons, or the shortcut keys for Menu Items, so it’s generally good practice not to assign checkboxes or radio buttons to icon menu items, as they will not be available.

If more than six Menu Items have been defined, a More item is included that, when selected, dis-plays the expanded menu. Pressing the Back button closes the icon menu.

❑The Expanded Menu The expanded menu is triggered when a user selects the More Menu Item from the icon menu. The expanded menu (shown in Figure 4-5) displays a scrollable list of only the Menu Items that weren’t visible in the icon menu. This menu displays full text, shortcut keys, and checkboxes/radio buttons as appropriate.

It does not, however, display icons. As a result, you should avoid assigning icons to Menu Items that are likely to appear only in the expanded menu.

Pressing Back from the expanded menu returns to the icon menu.

You cannot force Android to display the expanded menu instead of the icon menu. As a result, special care must be taken with Menu Items that feature checkboxes or radio buttons to ensure that they are either available only in the extended menu, or that their state information is also indicated using an icon or change in text.

❑Submenus The traditional “expanding hierarchical tree” can be awkward to navigate using a mouse, so it’s no surprise that this metaphor is particularly ill-suited for use on mobile devices. The Android alternative is to display each submenu in a floating window. For example, when a user selects a submenu such as the creatively labeled Submenu from Figure 4-5, its items are dis-played in a floating menu Dialog box, as shown in Figure 4-6.

Note that the name of the submenu is shown in the header bar and that each Menu Item is dis-played with its full text, checkbox (if any), and shortcut key. Since Android does not support nested submenus, you can’t add a submenu to a submenu (trying will result in an exception).

As with the extended menu, icons are not displayed in the submenu items, so it’s good practice to avoid assigning icons to submenu items.

Pressing the Back button closes the floating window without navigating back to the extended or icon menus.