Skip to Content
Android 9 Development Cookbook - Third Edition
book

Android 9 Development Cookbook - Third Edition

by Rick Boyer
October 2018
Intermediate to advanced
464 pages
15h 17m
English
Packt Publishing
Content preview from Android 9 Development Cookbook - Third Edition

How it works...

There are two basic steps here:

  1. Define the menu in XML
  2. Inflate the menu when the activity is created

As a good programming habit, we define the string in the strings.xml file rather than hard coding it in the XML. We then use the standard Android string identifier to set the title for the menu in step 3. Since this is a Settings menu item, we used the showAsAction="never" option so it wouldn't be shown as an individual menu option in the action bar. 

With the menu defined, we will use the menu inflater in step 4 to load the menu during the activity creation. Notice the R.menu.menu_main menu resource syntax? This is why we create the XML in the res/menu directory—so the system will know this is a menu resource.

In step 4, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Android Application Development Cookbook - Second Edition

Android Application Development Cookbook - Second Edition

Rick Boyer, Kyle Mew
Android High Performance Programming

Android High Performance Programming

Enrique López Mañas, Diego Grancini
Android Things Projects

Android Things Projects

Francesco Azzola

Publisher Resources

ISBN: 9781788991216Supplemental Content