Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use the ActionBar on older versions of Android? [duplicate]

Tags:

java

android

Possible Duplicate:
What is the equivalent of ActionBar in earlier sdk versions?

If I'm not mistaken, the Android guidelines say you should use the ActionBar for the global navigation within an app.

But at the same time, you typically want to target the oldest API possible for maximum compatibility.

I'm beginning development on an app and I set the target to Android 2.2.

Is it possible to use the action bar here? If not, what do i use?

Thanks Kevin

like image 211
Kevin Avatar asked Dec 09 '22 23:12

Kevin


1 Answers

Use ActionBarSherlock.

  • Make sure your project uses Android 4.0+ as the build target and that you have the compatibility/support library added. (You can right-click the project, select Android Toots > Add Support Library)
  • Download the ActionBarSherlock library project and import it into Eclipse.
  • Right-click your main project, select Properties, and select Android in the left pane. In the bottom half of the window, click the Add button and select the ActionBarSherlock project. Click OK.
  • Instead of using regular Activities and Fragments, you use ones from the Sherlock Library. They have the same names, but prefixed with "Sherlock" (SherlockActivity, SherlockFragment, etc.)
  • To access the actionbar in code, you call getSupportActionBar(). This returns either the regular actionbar (for Honeycomb and later) or the Sherlock actionbar (for pre-Honeycomb).
  • Theming instructions are on the ActionBarSherlock website.
like image 143
Karakuri Avatar answered May 01 '23 11:05

Karakuri