Creating contextual action mode menu

Some controls or regions in the user interface allow for additional actions to be performed. However, due to limited screen space, these actions need to be hidden until the user requests them.

How to do it...

  1. The first thing that needs to be done is to let the activity or fragment know that we want to display a popup menu when the user long-taps on a view:
    this.RegisterForContextMenu(someView);
  2. Then, following the pattern of the options menu, we create or inflate the menu items in the OnCreateContextMenu() method:
    public override void OnCreateContextMenu(
      IContextMenu menu,
      View view, 
      IContextMenuContextMenuInfo menuInfo) {
      base.OnCreateContextMenu(menu, view, menuInfo);
     MenuInflater.Inflate(Resource.Menu.Main_Options, ...

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.