Adding Drop down navigation to action bar in pre Honeycomb versions using Sherlock library

August 1, 2012

In the article titled “Adding Drop down navigation to action bar in Android“, we have seen how to add dropdown navigation to action bar for Android 3.0 ( Honeycomb ) and above.

In this article we will see how to add dropdown navigation to action bar for Android 2.x and above. Since action bar is available only with Android 3.0 and above, we will use Actionbar Sherlock library to create action bar in Android 2.x versions.

This application is developed in Eclipse (3.7.2 ) with ADT plugin ( 20.0.2 ) and Android SDK ( R20.0.1 )

1. Setup Actionbar Sherlock library in Eclipse IDE

Please see the article titled “Setting up Sherlock library for action bar in pre Honeycomb Android Applications

2. Create a new Android application project namely “ActionBarDropdownNavigationSherlock”

Create new Android Project

Figure 1 : Create new Android Project

3. Design application launcher icon

Design Application Launcher Icon

Figure 2 : Design Application Launcher Icon

4. Create a blank activity

Create a blank activity

Figure 3 : Create a blank activity

5. Enter MainActivity details

Enter main activity details

Figure 4: Enter main activity details

6. Delete Android’s support library

By default, Eclipse adds Android’s Support library to the project. We don’t want to use this library for this project. This library will be available in the folder “libs” in the name “android-support-v4.jar“. Delete this jar file from the “libs” folder.

7. Add Sherlock library to this project

  • Open Project Explorer
  • Right click the project   “ActionBarDropdownNavigationSherlock”
  • Open Properties
  • Select “Android” tab from the Properties Window
  • Then the given below screen will be appeared
  • Using Add button, add the Sherlock library to this project
Add Sherlock Library to this project

Figure 5 : Add Sherlock Library to this project

8. Update the class file src/in/wptrafficanalyzer/actionbardropdownnavigationsherlock/

package in.wptrafficanalyzer.actionbardropdownnavigationsherlock;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Toast;


public class MainActivity extends  SherlockActivity {

    /** An array of strings to populate dropdown list */
    String[] actions = new String[] {

    public void onCreate(Bundle savedInstanceState) {

        /** Create an array adapter to populate dropdownlist */
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getBaseContext(), R.layout.sherlock_spinner_item, actions);

        /** Enabling dropdown list navigation for the action bar */

        /** Defining Navigation listener */
        ActionBar.OnNavigationListener navigationListener = new OnNavigationListener() {

            public boolean onNavigationItemSelected(int itemPosition, long itemId) {
                Toast.makeText(getBaseContext(), "Current Action : " + actions[itemPosition]  , Toast.LENGTH_SHORT).show();
                return false;

        /** Setting dropdown items and item navigation listener for the actionbar */
        getSupportActionBar().setListNavigationCallbacks(adapter, navigationListener);


    public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
        getSupportMenuInflater().inflate(, menu);
        return super.onCreateOptionsMenu(menu);

9. Update the file AndroidManifest.xml

<manifest xmlns:android=""
    android:versionName="1.0" >

        android:targetSdkVersion="15" />

            android:theme="@style/AppTheme" >

                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />


10. Screenshot of the application in execution

Screenshot of the application in execution

Figure 6 : Screenshot of the application in execution

11. Download

12. Reference

How to hire me?

I am George Mathew, working as software architect and Android app developer at

You can hire me on hourly basis or on project basis for Android applications development.

For hiring me, please mail your requirements to

My other blogs

Android Knowledge Quiz

Ready to test your knowledge in Android? Take this quiz :

Tags: , , , , , ,

One Response to Adding Drop down navigation to action bar in pre Honeycomb versions using Sherlock library

  1. Android on September 17, 2012 at 4:44 pm

    A good one but the problem is that,it duplicates the “Bookmarks” menu option.from the snapshot we have 2 bookmarks, a menu and a menu option,what if i want the menu header to be bookmarks only without it being repeated in the options how do i go about it?

Leave a Reply to Android Cancel reply

Your email address will not be published. Required fields are marked *

Be friend at g+

Subscribe for Lastest Updates

FBFPowered by ®Google Feedburner