Chapter 11

Going a la Carte with Your Menu

In This Chapter

arrow Building an Options menu

arrow Creating a long‐press action

Every good Android application includes menus. If you have an Android device and you’ve downloaded a few applications from the Google Play Store, you’ve probably encountered plenty of menu implementations. You’ll recognize them by their icons or text in the action bar, or their text in the drop‐down overflow menu on the far right of the action bar.

Activities and fragments can both have menus, in which case they’ll both be combined into one. In this chapter, you add option and context menus to the fragments in the Tasks app, but you could just as easily add them to an activity, too.

Understanding Options and Context Menus

Android provides a simple mechanism for you to add menus to your applications. This is the Options menu (also known as the action bar menu). This is, most likely, the most common type of menu that you’ll work with. It’s the primary menu for an activity or fragment.

The Options menu is in the action bar at the top of the screen (read more about the action bar in Chapter 1). Figure 11-1 shows the Options menu with the overflow menu collapsed and expanded.

Figure 11‐1: The Options menu with (top) menu icons and (bottom) the overflow menu expanded.

Get Android App Development For Dummies, 3rd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.