How can I use a contextual action bar with the Android support library?

android, android-actionbar

Solution

What you want to use is ActionMode, http://developer.android.com/reference/android/support/v7/view/ActionMode.html, to implement the contextual action bar. The ActionMode is available in the ActionBarCompat library. Specifically you use ActionBarActivity#startSupportActionMode.

You can get a quick introduction in this document, http://android-developers.blogspot.com/2013/08/actionbarcompat-and-io-2013-app-source.html. See the section entitled "7. Add ActionMode callbacks".

A more complete tutorial is available here, http://developer.android.com/guide/topics/ui/menus.html#CAB.

Problem

I have a ListView in my ActionBarActivity that has items that can be long-pressed for additional actions. I currently am using `registerForContextMenu` and showing an ugly popup dialog, so I want to change it to use a contexual action bar. How can I do this? CHOICE_MODE_MULTIPLE_MODAL as well as a few other things seem to be API 11+.

Original source