Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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+.

like image 824
Steven Schoen Avatar asked Dec 01 '13 04:12

Steven Schoen


2 Answers

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.

like image 77
Matt Accola Avatar answered Sep 19 '22 20:09

Matt Accola


The Android API Guide for menus (same page that Matt cited) states that:

Note: The contextual action mode is available on Android 3.0 (API level 11) and higher and is the preferred technique for displaying contextual actions when available. If your app supports versions lower than 3.0 then you should fall back to a floating context menu on those devices.

If this is still true, then it means that Android does not support contextual action bars below API level 8. Can anyone please confirm if they have used it for Froyo or below?

like image 34
Price Avatar answered Sep 22 '22 20:09

Price