Implementing ActionBarSherlock In Android

In this tutorial, you will learn how to implement ActionBarSherlock into your Android Application. ActionBarSherlock automatically uses the native action bar when appropriate or wrap a custom implementation around your layouts. Using ActionBarSherlock allows you to easily develop an application with an action bar for every version of Android from 2.x and up. So lets begin…

Download ActionBarSherlock Library

Visit ActionBarSherlock website and download the Zip file provided. The extracted zip folder should contain the files shown below.

ActionBarSherlock Folder

Rename the folder “actionbarsherlock” to “ActionBarSherlockLib” and copy the folder into your workspace as shown on the screenshot below.

Insert ActionBarSherlock into workspace

Import ActionBarSherlock Library

To import ActionBarSherlock Library into Eclipse, go to File > Import > Select Existing Android Code into Workspace.

Click on Browse button and locate ActionBarSherlock Library in your workspace. Import ActionBarSherlock Library into your workspace by ticking the check box as shown on the screenshot below.

Import ActionBarSherlock Library

On successful import, you should have ActionBarSherlock Library in your Package Explorer as shown on the screenshot below.

Package Explorer ActionBarSherlock

To clear the errors, right click on the project and select Properties. Select Java Compiler and change the “Compiler compliance level” to 1.6. 

Eclipse Java Compiler

Implement ActionBarSherlock Library into Project

Create a new project in Eclipse File > New > Android Application Project. Fill in the details and name your project ActionBarSherlockTutorial.

Application Name : ActionBarSherlockTutorial

Project Name : ActionBarSherlockTutorial

Package Name : com.androidbegin.actionbarsherlocktutorial

Next, import ActionBarSherlock Library into your project. Go to your project properties by right clicking on your project > Properties > Android > Add > Select ActionBarSherlockLib > Apply > OK.

Add ActionBarSherlock Library

Open your and paste the following code.

package com.androidbegin.actionbarsherlocktutorial;

import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener;

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

public class MainActivity extends SherlockActivity {

	public void onCreate(Bundle savedInstanceState) {
		// Get the view from activity_main.xml

	public boolean onCreateOptionsMenu(Menu menu) {

		// First Menu Button
				.setIcon(R.drawable.help_button) // Set the menu icon

		// Second Menu Button
				.setIcon(R.drawable.like_button) // Set the menu icon

		// Third Menu Button

		return super.onCreateOptionsMenu(menu);

	// Capture first menu button click
	OnMenuItemClickListener HelpButtonClickListener = new OnMenuItemClickListener() {

		public boolean onMenuItemClick(MenuItem item) {

			// Create a simple toast message
			Toast.makeText(MainActivity.this, "Help Button", Toast.LENGTH_SHORT)

			// Do something else
			return false;

	// Capture second menu button click
	OnMenuItemClickListener LikeButtonClickListener = new OnMenuItemClickListener() {

		public boolean onMenuItemClick(MenuItem item) {
			// Create a simple toast message
			Toast.makeText(MainActivity.this, "Like Button", Toast.LENGTH_SHORT)

			// Do something else
			return false;

	// Capture third menu button click
	OnMenuItemClickListener ExitButtonClickListener = new OnMenuItemClickListener() {

		public boolean onMenuItemClick(MenuItem item) {
			// Create a simple toast message
			Toast.makeText(MainActivity.this, "Exit Button", Toast.LENGTH_SHORT)

			// Do something else
			return false;

We have created three actionbar menus with the codes above and on each menu click will show a simple toast message. You can perform other tasks such as showing an alert dialog, start an intent or place actions that have a global impact on the application.

We have prepared some sample icons for the menus. Insert your downloaded sample icons into your res drawable-hdpi.

Sample Icons

[wpfilebase tag=file id=82 tpl=download-button /]

Next, create an XML file for your MainActivity Graphical Layout. Go to res > layout > Right Click on layout > New > Android XML File

Name your new XML file activity_main.xml and paste the following code.


<RelativeLayout xmlns:android=""
    android:layout_height="match_parent" >

        android:text="@string/ActionBarSherlock" />


Next, change the application name and other texts. Open your strings.xml in your res > values folder and paste the following code.


    <string name="app_name">ActionBarSherlock Tutorial</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="ActionBarSherlock">ActionBarSherlock Tutorial</string>


In your AndroidManifest.xml, we need to change the theme style to “Theme.Sherlock“. Insert “splitActionBarWhenNarrow” to your activity to show actionbar at the bottom of the screen. Open your AndroidManifest.xml and paste the following code.


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

        android:targetSdkVersion="8" />

        android:theme="@style/Theme.Sherlock" >
            android:uiOptions="splitActionBarWhenNarrow" >
                <action android:name="android.intent.action.MAIN" />

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



ActionBarSherlock Tutorial ScreenShots

Source Code 

[purchase_link id=”7842″ text=”Purchase to Download Source Code” style=”button” color=”green”]

Latest comments

there is a lot of errors i got once i implement that actionbarsherlock project as a libraryinto one of my eclipse project. What should I do to resolve that case?Because the old support v4 is already removed from my project directory.


Implementing ActionBarSherlock In Android

Hi , in the androidmanifest whene i tried to change the Theme adding Eclipse told me that Theme.Sherlock not found !!!

Yns Abbassi

Implementing ActionBarSherlock In Android

remove support jar file from your application's libs folder. It's already added to the library's libs

Rowan Tarek

Implementing ActionBarSherlock In Android

Hi!What is the difference between simple action bar and actionbar Sherlock? I have used action bar without ActionbarSherlock library and it works fine. is there any extra functionality in this library?

Ubaid Gul

Implementing ActionBarSherlock In Android