Chapter 13 The Toolbar
Menus
The top-right area of the toolbar is reserved for the toolbar’s menu. The menu consists of action items
(sometimes also referred to as menu items), which can perform an action on the current screen or on
the app as a whole. You will add an action item to allow the user to create a new crime.
Your menu will require a few string resources. Add them to strings.xml (Listing 13.3) now. These
strings may seem mysterious at this point, but it is good to get them taken care of. When you need
them later, they will already be in place, and you will not have to stop what you are doing to add them.
Listing 13.3 Adding strings for menus (res/values/strings.xml)
Defining a menu in XML
Menus are a type of resource similar to layouts. You create an XML description of a menu and place
the file in the res/menu directory of your project. Android generates a resource ID for the menu file
that you then use to inflate the menu in code.
In the project tool window, right-click on the res directory and select New → Android resource file.
Change the Resource type to Menu, name the menu resource fragment_crime_list, and click OK
(Figure 13.3).