Creating an options menu
Android provides the user with the ability to display a special type of menu that contains a set of items that pertains to the entire app, instead of the current activity.
How to do it...
Adding an options menu to our app is very simple, and only two things are required: a menu structure and code to connect the menu with the activity. In order to use a menu layout file, a resource file needs to be added:
- First, we create a new XML file with the name of the menu, for example
Options.xml
, in themenu
folder under theResources
folder. - Then, we create the menu structure in this file, for example, create three menu items:
refresh
,settings
, andabout
.<?xml version="1.0" encoding="utf-8" ?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> ...
Get Xamarin Mobile Development for Android Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.