We know that, action bar is implemented in Android 3.0 ( Honeycomb or API Level 11) on wards.
But we can implement action bar in pre Honycomb versions upto API Level 7 using ActionBarCompat library available with Android support library revision 18.
In this article, we will see how to implement action bar in pre honeycomb versions using ActionBarCompat support library.
This application is developed in Eclipse 4.2.0 with ADT plugin 22.0.4
1. Create new Android application project
Application Name : ActionBarCompatDemo
Project Name : ActionBarCompatDemo
Package Name : in.wptrafficanalyzer.actionbarcompatdemo
Minimum Required SDK : API 8 : Android 2.2 ( Froyo )
Target SDK : API 17 : Android 4.2 ( Jelly Bean )
2. Setup ActionBarCompat library in Eclipse
Please refer the article titled “Android – Setting up ActionBarCompat support library in Eclipse”
3. Add reference to ActionBarCompat library
4. Update the file AndroidManifest.xml
Note : As shown in the highlighted line 15, the activity that implements the action bar should apply the style Theme.AppCompat or Theme.AppCompat.Light or Theme.AppCompat.DarkActionBar
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="in.wptrafficanalyzer.actionbarcompatdemo" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/Theme.AppCompat" > <activity android:name="in.wptrafficanalyzer.actionbarcompatdemo.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
5. Update the class MainActivity in the file src/in/wptrafficanalyzer/actionbarcompatdemo/MainActivity.java
Note : As shown in the highlighted line7, the activity should extend the class ActionBarActivity.
package in.wptrafficanalyzer.actionbarcompatdemo; import android.os.Bundle; import android.view.Menu; import android.support.v7.app.ActionBarActivity; public class MainActivity extends ActionBarActivity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
6. Screenshot of the application
7. Download Source code


I am George Mathew, working as software architect and Android app developer at wptrafficanalyzer.in
You can hire me on hourly basis or on project basis for Android applications development.
For hiring me, please mail your requirements to info@wptrafficanalyzer.in.
My other blogs
store4js.blogspot.com
hi in manifest file Theme.Appcompat not exits?
Hi Shashidhar,
It is already there in the article as well as in the attached source code.
Hi, I have downloaded and ran this app, all works fine. Then I added this line after setContentView(), getSupportActionBar().setTitle(“Title”); but it throws me NullPointerException. why?
can we use this method for min sdk 7 ?
“the activity that implements the action bar should apply the style Theme.AppCompat or..”
Thanks, that helped me out