Friday, May 11, 2012

Using The ActionBar Design-Pattern From Android Version 1.6 On And Higher

Now, as Android developers we are in a big break of UI-Design and usability. The fancy Holo theme from Android ICS lingers in the future but most of the devices runns still with 2.3. Without the ActionBar I wouldn't develope an app. Here is the way to overcome the shortcomings.


If you want to use the ActionBar design pattern you can do it with the great ActionBarSherlock library from Jake Wharton.

He has done a good job with the library and helps you out with any questions in his google group.
Have a look at his demo app at google play. It shows you most of the features.

ABS (ActionBarSherlock) is an extention to the official support package with the minimum API level of 7 or platform version 2.1.x.
So you need as a requirement at leased the android-support-v4.jar. That means you should have a closer look what this API offers you.

Steps to get you going

  1. Download the ABS library and unpack it.
  2. Import the ABS library.
    Start Eclipse, Import -> Android -> Existing Android Code Into Workspace
    In your Package Explorer you should see a project called ActionBarSherlock
    It has the Compiler compliance level 1.6 and in the libs folder you will find the android-support-v4.jar.
  3. Create a test project.
    New -> Android Projects
    Project Name: TestABS
    Build Target: Android 4.0.3
    Add the ABS-Library to your project.
    Right click on the project -> Properties -> Android -> Library -> Add... -> ActionBarSherlock
  4. Setting the sdk version and the theming.
    Edit the AndroidManifest.xml
    <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15"/>
    <activity ... android:theme="@style/Theme.Sherlock">
  5. Use the ABS base classes for the Activity
    public class TestABSActivity extends SherlockActivity {
Now you can start your AVD with lets say Android version 2.3.3 and you will see the ActionBar with the Holo theme.


The downloaded library package includes the sources for the demo app.
This is a good starting point to explore alle the capabilities of ABS.

APK-Size

  38 kB - Standard hello world
515 kB - ABS hello world


2 comments:

  1. minimum api level for ABS is 7!

    ReplyDelete
    Replies
    1. Thanks mate, I mixed up the java compiler level 1.6 with the Android API level.

      Delete