How to setup ActionBarSherlock in Android Project

ActionBarSherlock is an extension of the support library designed to facilitate the use of the action bar design pattern across all versions of Android with a single API.

This actionbar provides you these functionalities:

  1. Icon: The App Icon show our app’s identity.
  2. View Control: If your app displays data in different views, this segment of the action bar allows users to switch views.
  3. Action Buttons: Actions that don’t fit in the action bar are moved automatically to the action overflow. Long-press on an icon to view the action’s name.
  4. Action Overflow: Move less often used actions to the action overflow.

Steps to installation:

  • First you need to download  ActionBarSherlock Library from & extract.
  • Now copy folder actionbarsherlock into your eclipse workspace.
  • Now import project actionbarsherlock into workspace .
  • Now you have done with importing actionbarsherlock library into your workspace, now go for the actually creating project with this Action-bar.

Steps to create Project with actionbarsherlock:

  • Create New Android Project. e.g. I will name it “ActionBarSherlockDemo”.
  • Now, right click on your project, go to properties. Make sure “Is Library” checkbox is not checked. Now click on Add button from Android -> Library section, you will see Project Selection window. Here select project actionbarsherlock and click OK. You must clean this project before use.
  • You may get get error like  Jar mismatch! Fix your dependencies. In that case, remove “android-support-v4.jar” from your project and build both projects.
  • Go to Project manifest file. inside application tag put android:theme="@style/Theme.Sherlock" by replacing ‘AppTheme’
  • Now we need to make necessary changes to our so it could be able to display Action Bar, Your file should be something like this.

These changes are as follows:

  • import instead of and extend MainActivity by SherlockActivity.
  • import com.actionbarsherlock.view.Menu instead of android.view.Menu.
  • replace method getMenuInflater by getSupportMenuInflater.

Now your project is ready to run !!! You will see output like:

ActionBarSherlock simple

Steps to customize ActionBarSherlock:

Now we are going to add icons on ActionBarSherlock. e.g we will add two icons “Settings icon” and “Search icon

  • Take two icons and put it in the drawable folder of project resources.
  • In the menu folder, create or edit main.xml file. and paste the below code in that file. Here we need to also put respective icons for “Settings” and “Search” inside drawable folder of project resources.

    • To change color of action bar put following code in onCreateOptionsMenu method in “” file.

You will see output like:
ActionBarSherlock Custom

If you have found this Tutorial useful please share it in your circle.

You can download this tutorial code for free !!!

For any trouble with the code. Don’t forget to put the comment.

You may also like...

2 Responses

  1. girish says:

    hi sirji
    i follow all step but i getting error like R cannot resolve as type
    i use target 5.0.1 api level 21
    plz help me
    thnx in advance

Leave a Reply

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