Implementing Contextual Action Mode

The code you have written for deleting a crime via a floating context menu will work on any Android device. For instance, Figure 18.2 shows the floating menu on a device running Jelly Bean.

However, the recommended way to present contextual actions on newer devices is to have a long-press on a view put the screen into contextual action mode. When the screen is in contextual action mode, the items defined in your context menu appear in a contextual action bar that overlays the action bar. Contextual action bars are nice because they do not obscure the screen.

Figure 18.3  Contextual action bar appears on long-press

Implementing a contextual action bar requires a different set of code from a floating context ...

Get Android Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.