Adding ActionBarSherlock to Your Project

Please note:

I originally have written this post with ActionBarSherlock in mind. For most scenarios I recommend to switch to ActionBarcompat instead. If you start a new project I recommend to start using ActionBarCompat right away.

See this post to learn about migrating to ActionBarCompat:
How to migrate from ActionBarSherlock to ActionBarCompat

In my last post I had a look at how to set up a Fragment project that uses a master detail view. This week I am going to show you the necessary steps to make this project use the ActionBarSherlock library.

ActionBarSherlock is a library by Jake Wharton, that enables you to use action bars even on older devices without having to code an action bar from scratch. This library deals with all the details you do not want to care about. Even Googlers like Roman Nurik or Nick Butcher recommend to use this library and the Google IO app also makes use of this lib. So should you!

With this post I start my series about the action bar by simply adding an action bar to the project of my last post, adding some action items to it and explaining some basics of action bars. The focus of this post is mainly on getting ActionBarSherlock to run on your project. As such it is an introductory post about the action bar.

Since the action bar offers many functions and is the most important navigational component Android has, more posts about it will follow in the next weeks.

Getting ActionBarSherlock and adding it to Eclipse

The first thing you have to do, is to download the library from actionbarsherlock.com. After this unzip/untar it. The download contains three folders: library, samples and website. The samples folder contains four sample projects to showcase what you can do and to show you how to do it. You should have a look at them. The website folder contains the code of the project website. The library folder finally contains ActionBarSherlock’s source code.

Now go to Eclipse and add the ABS-library as an Android project. Do not use Eclipse’s import tool to import the ActionBarSherlock library – it would not work immediately and you would have to fix some settings. Instead use the project creation wizard of the Android Developer Tools.

Open File -> New -> Project -> Android Project From Existing Code.

Creating an Adnroid project from existing source

Creating an Android project from existing source

In the next screen select the folder, which Eclipse then uses to search for projects. If you select the ActionBarSherlock root folder, Eclipse suggests a list of projects to create. Leave the “library” project checked and uncheck all others:

Select the library project

Select the library project

Click “Finish” to create the project.

Eclipse will now create a new project named “library”. I prefer a more useful name, so select the project called “library” and hit F2 to rename the project. I have renamed the project in Eclipse to “ActionBarSherlock”, so all following screens will refer to this name.

Adding the library to your project

Now that ABS is a library project you have to tell your own project to use it. I will use the project of my last post for this. Go to FragmentStarter’s project settings and switch to the Android tab.

If necessary scroll down until you see the Library panel. Click “Add”:

Adding libraries to an Android project

Adding libraries to an Android project

In the next window all available library projects will be listed. Select ActionBarSherlock and click “Ok”.

Select ActionBarSherlock from the list of libraries

Select ActionBarSherlock from the list of libraries

When the window disappears the library should be listed in the library panel of the Android properties tab:

Check if the library has been added succesfully

Check if the library has been added succesfully

What is slightly annoying is that the Android Developer Tools do not use the name of a project to reference it, but instead point to the directory itself. And what’s even more annoying is that a symlink gets translated to its real path, which is bound to change more often than a symlink.

Should you ever want to change the directory, you have to delete the reference to the library with the old path and link to the newly imported library. But unless you do a fresh install for blog posts, this probably won’t happen too often :-)

That’s it. Your project bundles the lib from now on.

But wait a moment! If you have a look at your project, you will notice that it now sports a red warning icon. Go to the error tab and you will see lots of warnings. Eclipse states for Fragment, FragmentActivity and all the other classes of the support library, that they “cannot be resolved to a type”. Whoops!

Unknow type problems after adding ActionBarSherlock

Unknow type problems after adding ActionBarSherlock

The reason is, that ActionBarSherlock comes bundled with the library as well. And most of the time the support library added when following my post about fragments is different from the one bundled with ActionBarSherlock. In the console tab of Eclipse you see the message “Jar mismatch! Fix your dependencies” with the hashcodes of the mismatching files and where these files are stored:

[FragmentStarterProject] Found 2 versions of android-support-v4.jar in the dependency list,
[FragmentStarterProject] but not all the versions are identical (check is based on SHA-1 only at this time).
[FragmentStarterProject] All versions of the libraries must be the same at this time.
[FragmentStarterProject] Versions found are:
[FragmentStarterProject] Path: /opt/workspace/FragmentStarterProject/libs/android-support-v4.jar
[FragmentStarterProject] 	Length: 385685
[FragmentStarterProject] 	SHA-1: 48c94ae70fa65718b382098237806a5909bb096e
[FragmentStarterProject] Path: /opt/libs/ActionBarSherlock/library/libs/android-support-v4.jar
[FragmentStarterProject] 	Length: 349252
[FragmentStarterProject] 	SHA-1: 612846c9857077a039b533718f72db3bc041d389
[FragmentStarterProject] Jar mismatch! Fix your dependencies

To fix this, simply delete the support library from you project. Go to the libs folder, select the android-support-v4.jar file and delete it. You can still use the support library because it’s also part of the ABS project.

If you need a newer version of the support library than the one bundled with ActionBarSherlock, remove the support library from both projects and add it anew to the ActionBarSherlock project.

With this done your project is good again. The next step, of course, is to change some code.

Changing the types to their ActionBarSherlock counterparts

Just adding the library won’t magically add an action bar to your project. Instead you have to change some of your code.

The first thing you have to do, is to change the classes from which you inherit. Instead of Activity use SherlockActivity, instead of FragmentActivity use SherlockFragmentActivity, instead of Fragment use SherlockFragment and so on. Now do this for the two activities and the two fragments you created while reading the last post.

You will notice that the ItemDetailActivity won’t compile any more. Whenever you add ActionBarSherlock to an existing project, this is bound to happen. Why is that?

Have a look at the error message Eclipse is displaying: “Cannot override the final method from SherlockFragmentActivity“. The method is the following:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
   // ...
}

ActionBarSherlock overrides every method of it’s superclasses that takes either a Menu, MenuItem or MenuInflater object of the android.view package as parameter and declares those methods as final. You need to know that all the items in an action bar are actually menu items. Thus only by doing it this way ActionBarSherlock can take control of all the menu-handling and change it for older Android versions.

While the error message might sound bad, it actually isn’t. ActionBarSherlock provides
for every final method another method with the same name and the same number of arguments. Even the class names of the arguments are the same. Only the packages differ.

This way ActionBarSherlock makes migration of existing projects very easy. You can keep your methods and do not have to change and adjust any logic. Simply delete all import statements to the menu-related classes of the package android.view. After this hit Ctrl-O to optimize and correct the import statements and when Eclipse displays the list of imports to choose from, choose those of the ActionBarSherlock library:

Choose ActionBarSherlock's classes for imports

Choose ActionBarSherlock’s classes for imports

If you do this for ItemDetailActivity the warnings disappear. Whenever you use Eclipse (or any other IDE for that matter) to generate the import statements for you, take care to select the types of the ActionBarSherlock library. Those all start with com.actionbarsherlock.

Now that your code looks fine, you should try to run the project. Whether this run is successful or not depends on the Android version of your device. If you run this code on a device with at least Android 4.0 everything runs fine. But not so on older devices. Here you will get a Force Close dialog due to an IllegalStateException:

java.lang.IllegalStateException: 
      You must use Theme.Sherlock, 
      Theme.Sherlock.Light, 
      Theme.Sherlock.Light.DarkActionBar, 
      or a derivative.

Gladly the exception is pretty specific: You have to use one of the Sherlock themes to get your project to run. ActionBarSherlock needs many definitions to get the action bar styled correctly. Thus it needs these styles and you have to use the ABS themes. You can use your own theme, of course, but you must use one of Sherlock’s themes as a base for yours. See the Sherlock theming guide for more information on this.

Since adding the action bar to older devices is the reason to use ActionBarSherlock in the first place, you have to change the theme. Change your AndroidManifest.xml file to use a Sherlock theme:

<application
   android:allowBackup="true"
   android:icon="@drawable/ic_launcher"
   android:label="@string/app_name"
   android:theme="@style/Theme.Sherlock.Light" >
   <!-- ... -->
</application>

Now finally the app runs fine. And yes, there is an ActionBar. As you can see it works fine on current as well as on older devices:

Initial action bar on a 2.1 device

Initial action bar on a 2.1 device


Initial action bar on a 4.2 device

Initial action bar on a 4.2 device

Adding items to the ActionBar

The action bar is basically what the old menu was before Honeycomb. This means that you have to create a menu to see an action bar.

Create a file with the name activity_itemlist.xml in the folder /res/menu and add the following code to it. This file describes the structure of your action bar:

<menu xmlns:android=
      "http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/add_item"
        android:icon="@drawable/ic_action_add"
        android:showAsAction="ifRoom"
        android:title="@string/add_item"
        android:titleCondensed="@string/add_item">
    </item>
    <item
        android:id="@+id/about"
        android:icon="@drawable/ic_action_info"
        android:showAsAction="never"
        android:title="@string/about"
        android:titleCondensed="@string/about">
    </item>

</menu>

Note: I use icons from the icon pack “Android Developer Icons 2″ of opoloo. The values I use for the android:icon attributes are specific to this icon pack. As soon as you want to try this code, you have to prepare icons that match this code or change the attribute value to fit your icons. See the appendix for more on this.

Only the xml file won’t suffice. You also need to override the onCreateOptionsMenu() method to inflate this file:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
   MenuInflater inflater = getSupportMenuInflater();
   inflater.inflate(R.menu.activity_itemlist, menu);
   return true;
}

This is the result when you run the project again. Note the differences between the 2.1 device and the 4.2 device:

Action bar with icons running on a 2.1 device

Action bar with icons running on a 2.1 device after pressing the menu button


Action bar with icons running on a 4.2 device

Action bar with icons running on a 4.2 device

The overflow menu

When you compare the screenshots of the previous section, you quickly understand what the so-called overflow menu is. This is the menu hidden behind the three dots are the far end of the action bar on modern devices.

Android shows as many items as it can directly on the action bar. But especially on phones the place for action items is quite limited. Thus Android shows all those items, that do not fit on the action bar directly, in the overflow menu. You can also tell Android to put items in the overflow menu regardless of the space. You can do so by using the value never for the attribute android:showAsAction of these items. More on this attribute later on.

The items of the overflow menu are only visible if you click the three dots on the right of the action bar or press the menu button on those devices that have such a button.

The three dots appear only on devices without a menu button. That’s the way to indicate to the user that more items are available and it’s also the only way how users can access these items. On devices with a menu button on the other hand you do not have any indicator, but users can always check if an overflow menu is present by clicking the menu key. I actually think the solution for devices without menu button is way better than the solution on devices with a menu button. On these latter devices users always have to guess if an overflow menu is present or not. Alas Samsung, the vendor that sells by far the most Android devices, still ships devices with menu buttons :-(

Sort your items by importance so that the most important actions are visible all the time. Those actions are the ones your users are most likely to perform on this screen. Think thoroughly about the importance of each item.

Other items should always be in the overflow menu, no matter how much space is left. For example if your app has an about screen, or some license info for the open source libs you use (well, ActionBarSherlock for example) or some information about what has changed with the recent version, I would put all those items into the overflow menu – no matter how much screen estate you have left.

The Android design page has some more guidance on this on their action bar pattern page and also shows you roughly how many items fit on the screen for some selected devices.

Use the android:icon as well as the android:title attribute

As you can see the action bar shows only an icon for the “Add Items” action. But that doesn’t mean that you should neglect the strings. First of all these strings are used for screenreaders so that visually impaired people still can use your app. And secondly, if users do not understand an icon immediately, they can longpress those icons until a hint appears that displays the text. Of course this hint is no excuse for confusing icons!

Another thing to note. Overflow menu items show only text. But not so on older devices. There you see the icon and the text. So always provide values for android:icon and for android:title!

Use android:showAsAction to define the appearance of the action items

The item element of the xml file for the action bar can contain four attributes that are only relevant for the action bar: android:showAsAction, android:actionLayout, android:actionViewClass and android:actionProviderClass. Of these I describe only the frst here, the other three are a topic for an extra post.

You can use the attribute android:showAsAction to decide which icons to display and in which way. It can take the following five values:

Possible values for the android:showAsAction attribute
Value Meaning
ifRoom Display item if enough room is left for this item
always Display this item, regardless of the existing place
never This item is not displayed in the action bar directly but in the overflow menu
withText Display the icon together with the title text
collapseActionView Only relevant for collabsible action views – not covered in this post

As a rule of thumb you should always use ifRoom, if you want the icon to be part of your action bar and you should use never if you want the item to always be part of the overflow menu.

The Android documentation for menu resources explicitly urges you to use always with great care. You should use this attribute only if the element is absolutely necessary. If you use this on multiple items and the place in the action bar is too small to do this properly Android displays overlapping icons. In this case the items are even less accessible than those of the overflow menu.

While you have to pick one of the first three, you can combine these with the value withText. This value decides whether Android shows only the icon or the icon plus the text of the android:title attribute. But Android does show the text only, if enough room is left.

As an example change the menu file to the following code:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
   <item
      android:id="@+id/add_item"
      android:icon="@drawable/ic_action_add"
      android:showAsAction="ifRoom|withText"
      android:title="@string/add_item">
   </item>
   <item
      android:id="@+id/reload_list"
      android:icon="@drawable/ic_action_reload"
      android:showAsAction="ifRoom|withText"
      android:title="@string/reload_list">
   </item>
   <item
      android:id="@+id/about"
      android:icon="@drawable/ic_action_info"
      android:showAsAction="never"
      android:title="@string/about">
   </item>
</menu>

Now these are the resulting screens depending on the Android version:

Action bar with multiple icons running on a 2.1 device

Action bar with multiple icons running on a 2.1 device


Action bar with multiple icons running on a 4.2 device

Action bar with multiple icons running on a 4.2 device after selecting the overflow menu

As you can see on phones Android still only displays the icons. Note what happens on small devices that have no menu button. Android had to put the second item into the overflow menu because it had not enough place for it. On devices with a menu button the second item would be directly visible in the action bar.

This is what the same app looks like on a tablet:

Action bar with multiple icons and text running on a 4.2 tablet

Action bar with multiple icons and text running on a 4.2 tablet

Now the withText value makes a difference. While I like items to display text on tablets, it is very unusual. Have a look at other apps to see how they do it, before you decide whether to display text or not. But do not use text to gloss over weaknesses in your icon design.

Dealing with user input

So far you have created the action bar and made it look right. But when you click on an item, nothing happens.

What you have to do is to implement the onOptionsItemSelected() method. You do this as you always did for menu item selections:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
   // Handle item selection
   switch (item.getItemId()) {
      case R.id.add_item:
         // do s.th.
         return true;
      case R.id.about:
         // do s.th.
         return true;
      default:
         return super.onOptionsItemSelected(item);
   }
}

Action bar interaction is like any other user interaction and all the usual rules about the UI thread apply. So don’t put any stuff in here that’s long-lasting. Use Loaders, AsyncTasks, IntentServices or whatever you prefer for the specific job to do the heavy lifting.

What’s next?

In this first part of the ActionBar tutorial you have changed your project so that your activities and fragments now inherit from ActionBarSherlock’s classes and then made it compile and run.

After this you added items to the action bar, learned about the overflow menu and about the ActionBar-related attributes of the menu xml files. But with this you barely scratched the surface of what the action bar covers.

According to the design guidelines the “action bar is one of the most important design elements you can implement”. No wonder it features all sorts of possibilities. And, yes, it brings with it some complexity as well. So there is more to the action bar than just this post.

In the next post I am goig to cover the different navigation types the action bar supports. After this I will write yet another post about the so-called contextual action bar.


Appendix

As mentioned all icons that I use are icons of opoloo’s Android Developers Icons 2. You have to either get this pack, create icons for yourself or download the “Action Bar Icon Pack” from the design site. The latter icon pack contains no “Add” icon, so you have to adapt the XML.

You can also use totally inappropriate icons and hassle with the design later on. For the sake of following this tutorial you could use something like @android:drawable/ic_menu_add. But you should never use these for anything else than for just getting on with this tutorial.

You have to add the icons you want to use to the respective folders within your /res folder. For details on how to name these folders see the Android documentation about providing resources.

Share this article:

You can leave a response, or trackback from your own site.

38 Responses to “Adding ActionBarSherlock to Your Project”

  1. Marty Ballard says:

    I believe I found a small error. “Create a file with the name activity_item_detail.xml in the folder /res/menu ”

    I believe the file name should be “activity_item list.xml”

    Great tutorial, waiting for the next one.

    Marty

  2. mixalis says:

    Great tutorial! I want to ask you one thing. When i delete the support.v4 library all the errors where fixed and the app runs perfect! This means that i can use sherlock library and change activity to sherlockActivity and so on , only when i want to use extra features which does not exist in pre Honeycomb? I am asking this because in the beginning i started changing all of my activities and fragments even though i didn’t want any extra feature.

    • I’m not sure, if I understand you correctly. The v4 support library is needed to use stuff that was only introduced later to earlier API versions. E.g. Loaders or Fragments. It also contains some classes that are useful no matter which API version you use but that are not part of the standard API (yet). For example the ViewPager.

      ActionBarsherlock on the other hand is only needed if you want to use the ActionBar on older API levels as well.

      Given the distribution of API levels that Google publishes regularly, I recommend to use both, ABS and the v4 support library.

      ActionBars are a very established pattern that ease the creation of a recognizable UI. Users come to expect it for most kinds of apps.

      And using the support library helps you keep the code unified. E.g. by using Fragments. And it is of course also a requirement for using ActionBarSherlock.

  3. mixalis says:

    Ok thank you very much! After test it for a while i understand how it works!

  4. Barry says:

    Thank you so much for this article :o)

  5. telina says:

    I think I love you!
    Thank you so much, took me way too long to try embedding it by myself :x

  6. rv says:

    Thanks for this tutorial, how would you implement a master-detail view inside of a tab? (since an activity is already hosting the tabs/fragments class)?

  7. linus.du says:

    Why I got a error “missing required library: ‘libs/android-support-v4.jar’” after I delete this jar file from my project. Do you know how can I fix this problem? Can you help me ?

  8. tanou says:

    Great tutorials, very complete and clear. This avoid me to waste lots of time into useless research. And thank you for you’re whole work, this blog is really helpful. Keep going!

  9. yudayyy says:

    Thank you so much, I am on my way learning develop android application. Keep posting useful tutorial Mr. Rittmeyer!

  10. JR Galia says:

    This is very helpful for newbie in android programming.

  11. Alobroj says:

    Thanks for tutorial,
    clear, easy to understand.

  12. Bhargav says:

    I use this lib in my project. i use 3 tab in actionbar. now i want to change the height of tab. i am not getting solution if you have plz tell me.. i try custom tab but actionbar tab height still not change.

  13. Ramesh Gundala says:

    Thanks, Its very usfull in my projec.

  14. Hannah says:

    There’s no library folder in v4.4.0. There’s only:
    – actionbarsherlock
    – actionbarsherlock-fest
    – actionbarsherlock-i18n
    – actionbarsherlock-samples
    – website

    Is this the version you used? I can’t get past the first step.

  15. Hendrik says:

    Hey thanks for the tut, one question. When I press CTRL-O to import the actionbarsherlock there is no actionbarsherlock option

  16. Adrian says:

    Im getting “cannot override the final method from sherlockactivity ” why ? help please

  17. Amal says:

    You may well have added a small description to change the app theme to actionbar theme in the manifest.(Your blog is really informative and standard).

  18. saurav says:

    Hi Wolfram Rittmeyer, I am trying to execute aerogear aerodoc android application, it requires ActionBarSherlock and I have add actionbarsherlock libary to my application as you have given instruction but it is showing red spot error and when I have gone with build path I have seen that it is indicating actionbarsherlock.jar is missing, I stucked kindly help me to sort out this problem

  19. Stefan says:

    Hello,

    it dont works for me );
    knows somebody how can i fix that?

    Description Resource Path Location Type
    android.app.ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 368 Java Problem
    android.app.ActionBar.NAVIGATION_MODE_LIST cannot be resolved to a type ActionBar.java /actionbarsherlock/src/com/actionbarsherlock/app line 73 Java Problem
    android.app.ActionBar.NAVIGATION_MODE_STANDARD cannot be resolved to a type ActionBar.java /actionbarsherlock/src/com/actionbarsherlock/app line 66 Java Problem
    android.app.FragmentTransaction cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 348 Java Problem
    actionBarWidgetTheme cannot be resolved or is not a field ActionBarSherlockNative.java /actionbarsherlock/src/com/actionbarsherlock/internal line 199 Java Problem
    android.app.ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 348 Java Problem
    android.app.FragmentTransaction cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 331 Java Problem
    android.app.ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 331 Java Problem
    android.app.ActionBar.DISPLAY_HOME_AS_UP cannot be resolved to a type ActionBar.java /actionbarsherlock/src/com/actionbarsherlock/app line 112 Java Problem
    android.app.ActionBar.DISPLAY_SHOW_HOME cannot be resolved to a type ActionBar.java /actionbarsherlock/src/com/actionbarsherlock/app line 97 Java Problem
    android.app.ActionBar.DISPLAY_USE_LOGO cannot be resolved to a type ActionBar.java /actionbarsherlock/src/com/actionbarsherlock/app line 88 Java Problem
    android.app.ActionBar.NAVIGATION_MODE_TABS cannot be resolved to a type ActionBar.java /actionbarsherlock/src/com/actionbarsherlock/app line 79 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 399 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 394 Java Problem
    ActionMode cannot be resolved to a type ActionBarSherlockNative.java /actionbarsherlock/src/com/actionbarsherlock/internal line 274 Java Problem
    android.view.ActionMode cannot be resolved to a type ActionBarSherlockNative.java /actionbarsherlock/src/com/actionbarsherlock/internal line 235 Java Problem
    android.view.ActionMode cannot be resolved to a type ActionBarSherlockNative.java /actionbarsherlock/src/com/actionbarsherlock/internal line 243 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 389 Java Problem
    android.view.ActionMode cannot be resolved to a type ActionBarSherlockNative.java /actionbarsherlock/src/com/actionbarsherlock/internal line 251 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 384 Java Problem
    android.app.FragmentTransaction cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 368 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 424 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 414 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 419 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 409 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 404 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 451 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 456 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 441 Java Problem
    android.app.ActionBar.DISPLAY_SHOW_CUSTOM cannot be resolved to a type ActionBar.java /actionbarsherlock/src/com/actionbarsherlock/app line 132 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 446 Java Problem
    android.app.ActionBar.DISPLAY_SHOW_TITLE cannot be resolved to a type ActionBar.java /actionbarsherlock/src/com/actionbarsherlock/app line 124 Java Problem
    android.app.ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 435 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 435 Java Problem
    android.app.ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 429 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 429 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 461 Java Problem
    ActionMode cannot be resolved to a type ActionBarSherlockNative.java /actionbarsherlock/src/com/actionbarsherlock/internal line 316 Java Problem
    ActionMode cannot be resolved to a type ActionBarSherlockNative.java /actionbarsherlock/src/com/actionbarsherlock/internal line 310 Java Problem
    ActionMode cannot be resolved to a type ActionBarSherlockNative.java /actionbarsherlock/src/com/actionbarsherlock/internal line 304 Java Problem
    ActionMode cannot be resolved to a type ActionBarSherlockNative.java /actionbarsherlock/src/com/actionbarsherlock/internal line 299 Java Problem
    ActionMode cannot be resolved to a type ActionBarSherlockNative.java /actionbarsherlock/src/com/actionbarsherlock/internal line 294 Java Problem
    ActionMode cannot be resolved to a type ActionBarSherlockNative.java /actionbarsherlock/src/com/actionbarsherlock/internal line 289 Java Problem
    ActionMode cannot be resolved to a type ActionBarSherlockNative.java /actionbarsherlock/src/com/actionbarsherlock/internal line 284 Java Problem
    ActionMode cannot be resolved to a type ActionBarSherlockNative.java /actionbarsherlock/src/com/actionbarsherlock/internal line 279 Java Problem
    ActionMode cannot be resolved to a type ActionBarSherlockNative.java /actionbarsherlock/src/com/actionbarsherlock/internal line 348 Java Problem
    ActionMode cannot be resolved to a type ActionBarSherlockNative.java /actionbarsherlock/src/com/actionbarsherlock/internal line 343 Java Problem
    ActionMode cannot be resolved to a type ActionBarSherlockNative.java /actionbarsherlock/src/com/actionbarsherlock/internal line 333 Java Problem
    ActionMode cannot be resolved to a type ActionBarSherlockNative.java /actionbarsherlock/src/com/actionbarsherlock/internal line 328 Java Problem
    ActionMode cannot be resolved to a type ActionBarSherlockNative.java /actionbarsherlock/src/com/actionbarsherlock/internal line 323 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 26 Java Problem
    android.app.ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 18 Java Problem
    android.app.ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 16 Java Problem
    android.app.ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 16 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 31 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 28 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 27 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 49 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 44 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 39 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 32 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 65 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 60 Java Problem
    android.app.ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 54 Java Problem
    android.app.ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 54 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 80 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 85 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 70 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 75 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 103 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 108 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 91 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 123 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 128 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 113 Java Problem
    AccessibilityNodeInfo cannot be resolved to a type IcsAdapterView.java /actionbarsherlock/src/com/actionbarsherlock/internal/widget line 893 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 118 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 141 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 146 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 133 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 138 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 156 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 150 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 166 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 161 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 176 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 171 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 186 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 181 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 196 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 191 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 206 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 201 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 216 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 211 Java Problem
    android.app.ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 224 Java Problem
    ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 221 Java Problem
    android.app.ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 225 Java Problem
    android.app.ActionBar cannot be resolved to a type ActionBarWrapper.java /actionbarsherlock/src/com/actionbarsherlock/internal/app line 229 Java Problem
    AccessibilityNodeInfo cannot be resolved to a type SearchView.java /actionbarsherlock/src/com/actionbarsherlock/widget line 1300 Java Problem

  20. Zaid Jaber says:

    Hi sir …
    i am have 1 error : i am reach to play my app … and have 1 error

    that’s error getMenuInflater().inflate(R.menu.main, menu);

    the latest menu = this give error Why??

    • You should post questions like that on SO. And you should include a full description of your problem and all relevant source snippets that could be helpful (in your case the menu xml file (main.xml) you are inflating and all of the onCreateOptionsMenu() method).

      And state what “gives error” means. Doesn’t compile? Throws exception during runtime? Be specific when posting questions like that. If you ask questions with enough details, you will usually get answers very fast on Stackoverflow.

  21. Zaid Jaber says:

    Ok … i am sry …
    i have error in main activity when i change the fragmentactivity to sherlockfragment activity ….

    @override
    Public boolean oncreateoptionmenu(menu menu) { (((((((((((((((error for all from on create to menu….))))))))))))))))
    // inflate the menu;this adds items to the action bar if is present
    getmenuinflater().inflate(R.menu.main, menu);
    return true;

    my app name : anfal

    Project Name : ABSListViewFragmentTabs

    Package Name : com.androidbegin.abslistviewfragmenttabs

    navigation type : Fixed tabs + swipe
    thank u …

  22. Zaid Jaber says:

    i have organize imports ….
    and the error change to inflate …..

  23. Shihab Uddin says:

    Thanks for super Tutorial.

    I can’t add android:theme=”@style/Theme.Sherlock.Light” in manifest file.

    So, can’t run the below API 11 device. I runs my code on 4.1.2 samsung galaxy s3. I add a jar file with my project which can be found after importing ABS Libs in Eclipse —>> ABSLibs > Libs > ABSJAR FILE.

    when run this below API 11 lets say 2.3.3 emulator I got an error like,

    10-12 03:16:10.540: E/AndroidRuntime(1483): FATAL EXCEPTION: main
    10-12 03:16:10.540: E/AndroidRuntime(1483): java.lang.NoClassDefFoundError: com.actionbarsherlock.R$styleable
    10-12 03:16:10.540: E/AndroidRuntime(1483): at com.actionbarsherlock.internal.ActionBarSherlockCompat.generateLayout(ActionBarSherlockCompat.java:973)

    Help me to solve this issue.

    • If you added ABS as a project to Eclipse and added as a library to your project you should be able to select the Theme within your AndroidManifest.xml.

      The error message you receive, shows that you are missing ActionBarSherlock’s generated R.java file. This should be within the gen folder of your project.

      Please add your configuration – you probably skipped just one tiny step.

  24. Would just like to say thank you for such a detailed and helpful tutorial. Been struggling with adding the Action Bar Sherlock, or just a Dependency Project to Eclipse in general. This was very helpful. Thank you again.

    • I’m glad I was of help. For new projects though, I would recommend to use ActionBarCompat. This library is made by Google and part of Google’s support package. I haven’t done any post about it yet and have no time to do one in the near future. Because Google now provides an official backwards compatibility library for the ActionBar, ActionBarSherlock will no longer get any updates.

      The currently existing sample projects on Bitbucket and also all my future sample projects will make use of ActionBarCompat. Thus you might want to have a look at them to understand how to use ActionBarCompat.

  25. gumuruh says:

    which version of actionbarsherlock do you use?
    because I found no folder called as “library” for the latest version right now…

    please write down the version you use, Wolfram?

Leave a Reply

You can also subscribe without commenting.