Actionbar implementation in earlier Android versions

 

The ActionBar was introduced in Android 3.0 (API 11) and enable us to develop applications with a more fluid navigation using Fragments. Ever since, we are using the Action Bar in pretty much every application.

The question is, how to be able to implement the Action bar in earlier < 3.0 API’s ?

The support library which enables us to use Fragments for devices with API<3 is great and does the work just like we want and need. but what about action bar support? it’s not out of the box even in the support library. the excepted method of implementing Action bar for those earlier versions is actionbarsherlock(or ABS) just to keep things short.

The ABS is an open-source expansion of the Android support library and it enables us to write application without having to make a implicit adjustment to out activities in order to support Action bars.

The usage is simple:

1. download the project from the ABS website at : http://actionbarsherlock.com/

2. inside the archive you’ll find a folder named library, you’ll only need this as a project to be included in the build path of your application.

3. start a new project (create from existing code) and choose the library folder which you’ve extracted from the download archive.

4. make sure that the manifest for your project and the library project matches in the minSDK and targetSDk versions

5. on the properties of your project – > android –> at the bottom you need to include the library to the build path, the project will rebuild in order to have all the needed references.

6. in API 4+ there’s the theme issue (Hollo.Dark, Hollo.Light etc..) , you need to make sure that each activity in your application has the reference to the style :

android:theme="@style/Theme.Sherlock.Light"

* or any other ABS theme which come ready to use in the library

7. In your app , make sure that instead of extending Activity class, you are extending the SherlockActivity class.

8. from now on you are using the support library which comes within the ABS library, so please make sure that all the native references are updated, for example: Menu, MenuInflater,MenuItem:

 

import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;

9. in order to enable Home as enabled for the back button please user :

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

instead of:

getActionBar()

And that’s it, you’re golden

Comments

Popular posts from this blog

Spinner VS AutoCompleteTextView

How to update UI from a different thread

Utilizing Http response cache