Creating contextual action mode menus

The action bar provides the user with a set of actions; however, these actions are usually just the most commonly used. Sometimes, the context of the app changes, so the presented actions need to adjust to what is commonly used in the new context.

How to do it...

There are a few steps to implementing a contextual action bar:

  1. The first step is to implement the ActionMode.ICallback interface. This interface can either be implemented in a new, separate class or on the actual activity or fragment:
    public class MainActivity : AppCompatActivity, ActionMode.ICallback { public bool OnCreateActionMode( ActionMode mode, IMenu menu) { } public bool OnPrepareActionMode( ActionMode mode, IMenu menu) { } public bool OnActionItemClicked( ...

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.