O'Reilly logo

Android App Development For Dummies, 3rd Edition by Michael Burton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required