Adding actions to ActionBar

With Android 3.0 (Honeycomb, API level 11), Android introduced a uniform title, such as a widget that docks to the top of the screen, called ActionBar. It allows apps to add activity-specific actions to the top of the device screen, just below the status bar. We will define two actions for the POIListActivity class: New, to create a new POI, and Refresh, to refresh the cache of POIs from the device's local storage.

The Activity class provides the following virtual methods that can be overridden to add actions:

Virtual Method

Description

OnCreateOptionsMenu

It allows the creation of the actions either through API calls or through inflating an XML definition

OnOptionsItemSelected

It is called when an action in ...

Get Xamarin Mobile Application Development for Android - Second Edition 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.