--- title: Usage layout: default ---
Sticking with the theme of the official compatability library, ActionBarSherlock aims to allow the use of the action bar design pattern by mimicking the experience that would be found natively on Android Ice Cream Sandwich with as little effort as required.
Due to its use of the native action bar and its related classes on Ice Cream Sandwich, the library requires that both it and your project are compiled with Android 4.0 or newer. The project also requires that you are compiling with JDK 1.6 in both your editor and any build systems that you may be using.
Since the library is an extension of the official support library you must also have the android-support-v4.jar
referenced by your project.
There are two ways to leverage ActionBarSherlock in your projects:
library/
folder as the existing source. Then, in your project properties, add the created project under the ‘Libraries’ section of the ‘Android’ category.If you use maven to build your Android project you can simply add a dependency for this library.
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>library</artifactId>
<version>4.0.0</version>
<type>apklib</type>
</dependency>
Make sure you also include r.jakewharton.com/maven/release/ in the repositories section of your pom.xml
.
When creating an activity to use the action bar on all versions of Android, you must declare your activity to extend any of the activity classes that start with 'Sherlock' (e.g., SherlockActivity
, SherlockFragmentActivity
). Interaction with the action bar is handled by calling getSupportActionBar()
(instead of getActionBar()
).
The API exposed by the ActionBar
instance is an exact duplicate of that which the native method exposes. Refer to its documentation as well as the articles on how to utilize its functionality in the "Related Links" section.
In order to provide functionality that was not available on version of Android prior to 3.0, the library includes and uses a lot of classes that are named the same as their native counterparts. The three most common are:
com.actionbarsherlock.app.ActionBar
com.actionbarsherlock.view.Menu
com.actionbarsherlock.view.MenuItem
It is important to ensure that you are using these types where appropriate since they contain the additional functionality required to support the action bar.
NOTE: The majority of errors regarding the @Override
-ing of methods from the activities are a result of using the incorrect imports. All of the classes which exist in the com.actionbarsherlock.*
package whose names match that of a native class extend from that native class and as such can be used in their place.
This library was meant to be as behind-the-scenes as possible and require a minimal amount of changes to support. The core usage of the action bar itself is no different than if you were interacting with the native action bar.
Be sure to also visit the following pages:
The following links are useful information on how to operate the native action bar. Other than the small tweaks mentioned on this page, the entire API is exactly the same.
getSupportActionBar()
exposes.