An important window feature named Action Bar was introduced in Honeycomb (API Level 11) and post Honeycomb devices. It provides a dedicated space for identifying the application brand and user location, and a consistent navigation. However, Action Bar is not available for pre-Honeycomb devices. But ActionBarSherlock which is an extension of the compatibility library designed to facilitate the use of the action bar design pattern across all versions of Android with a single API. In short, what it does is help you implement Action Bar for all devices starting from Android 1.6. This tutorial will help you create Action Bar for Android 2.2. I have created a Progress Bar while downloading file from Internet and Menus.

Adding ActionBarSherlock Library to your New Project

Step 1. Download latest package of ActionBarSherlock. Create a new Android Project from existing source. The location of the source should be the library folder of ActionBarSherlock. Make sure you have unzipped ActionBarSherlock in your eclipse installation folder.

Android Project

Create new Project from existing file system

Click next and choose the build target. The build target should be atleast API Level 14. Click next and choose the minimum SDK version which I have choosen 8.
Android Project Build Target

Choose Build Target greater than API Level 14

Now we have to add android-support-v4 support library. Add this library to this project. Learn how to do this. Now finally, choose Project->Properties->Android and check the Is Library box and press OK. Move to the next step.
Android Project as Library

Check Is Library box and click OK

Step 2. Create a new project in which you have to implement Action Bar with Build Target API greater than 14. Click on Project->Properties->Android->Click on Add near the Is Library and add the previous library you created.

Add custom library

Add ActionBarSherlock as library in your project

Now, we are good to go.

Download Project

Step3. In every Activity, you have to extend the class with SherlockActivity not Activity. The following code in the main activity creates menu items in the action bar. It is similar to previous post on creating menus. All we have to do is change the imports.
Note: Make sure to include styles.xml and AndroidManifest.xml given at the end of this post before running the project.

Update the main activity with the following code. The following snippet is an imitation of previous post Android Download File Progress Bar.

layout->main.xml

res->menu->menu.xml

values->styles.xml

AndroidManifest.xml

Run the Project on a Android 2.2 Device. You can see the action bar working on all devices. Below are screenshot of the final app.

Menu in Action Bar

Menu in Action Bar

Progress Bar in Action Bar

You can see the Progress Bar in the title bar.


I will continue to post more tutorials on implementation of ActionBarSherlock and other bakcward compatibility issues. Stay tuned.