I would like to remove ActionBarSherlock from my application and replace it with the standard ActionBarCompat.
How do I implement ActionBarCompat?
How do I migrate the Activites?
Which imports replace the ActionBarSherlock imports?
What are typical problems?
I did some migrating and wrote down all the issues I encountered. None were serious but took time to research. I was able to migrate a quite big application in a couple hours after knowing all this. May this help to speed up migration process.
How do I convert from ActionBarSherlock to ActionBarCompat?
Note: Since the Support Library's v22.1.0, the class ActionBarActivity is deprecated. You should use AppCompatActivity instead. Read here for more information: What's the enhancement of AppCompatActivity over ActionBarActivity?
== Switch the libraries ==
Go to app properties and remove ActionBarSherlock and add ActionBarCompat instead. This requires the v7 appcompat library to be present, see http://developer.android.com/tools/support-library/setup.html for details. Follow the instructions precisely, ActionBarCompat needs to be a library project.
Parallel does not work (easily) as a lot of attributes are in both libraries.
Do not be discouraged by hundreds of errors after replacing the libraries. The vast majority goes away automatically.
== Fix XML errors ==
First thing is to fix all XML errors to allow compiling and find other errors.
Replace the sherlock theme with ActionBarCompat Theme, e.g.
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
Remove double attr, e.g. <attr name="buttonBarStyle" format="reference" />.
For now remove all your individual action bar styles. See further down how to handle these.
== Fix build errors ==
Pick the easiest activities first. ActionBarCompat does not distinguish Activity and FragmentActivity, both are now ActionBarActivity.
Remove the ActionBarSherlock imports and extend to ActionBarActivity (import android.support.v7.app.ActionBarActivity;)
After saving, this should dramatically reduce errors in the activity.
Fix the errors around the menues first and disregard fragment errors for now, they should be going away later.
== Replacements ==
Imports:
import com.actionbarsherlock.app.SherlockActivity; -> import android.support.v7.app.ActionBarActivity;
import com.actionbarsherlock.app.SherlockFragmentActivity; -> import android.support.v7.app.ActionBarActivity;
import com.actionbarsherlock.app.SherlockFragment; -> import android.support.v4.app.Fragment;
import com.actionbarsherlock.app.SherlockListFragment; -> import android.support.v4.app.ListFragment;
import com.actionbarsherlock.app.SherlockListActivity; -> import android.support.v7.app.ActionBarActivity; (see ListActivity / SherlockListActivity)
import com.actionbarsherlock.view.Menu; -> import android.view.Menu;
import com.actionbarsherlock.view.MenuItem; -> import android.view.MenuItem;
import com.actionbarsherlock.view.MenuInflater; -> import android.view.MenuInflater;
import com.actionbarsherlock.view.Window; -> import android.view.Window;
import com.actionbarsherlock.widget.SearchView; -> import android.support.v7.widget.SearchView;
import com.actionbarsherlock.widget.SearchView.OnQueryTextListener -> import android.support.v7.widget.SearchView.OnQueryTextListener;
Code Replacements:
SherlockActivity -> ActionBarActivity
SherlockFragmentActivity -> ActionBarActivity
SherlockListActivity -> ListActivity (see ListActivity / SherlockListActivity)
SherlockListFragment -> ListFragment;
getSupportMenuInflater -> getMenuInflater
getSherlockActivity() -> getActivity()
com.actionbarsherlock.widget.SearchView.OnQueryTextListener() -> OnQueryTextListener (see SearchView)
m.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); -> MenuItemCompat.setShowAsAction(m, MenuItem.SHOW_AS_ACTION_ALWAYS);
Typical Code changes for ActionBarCompat
getActionBar() -> getSupportActionBar()
invalidateOptionsMenu() -> supportInvalidateOptionsMenu()
== Fragment ==
The fragment does not cater for ActionBarCompat functionality. This is a problem when trying to call getSupportActionBar.
This can be solved by using the onAttach method:
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
((ActionBarActivity)activity).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
Usually this is better controlled in the FragmentActivity.
== SearchView ==
This turned out to be a bit of a hassle.
Replace something like this:
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) searchItem.getActionView();
with
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
You also have to adjust your menu:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_search"
android:actionViewClass="com.actionbarsherlock.widget.SearchView"
android:icon="#android:drawable/ic_menu_search"
android:orderInCategory="80"
android:showAsAction="always|collapseActionView"
android:title="#string/action_search"/>
</menu>
with
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/action_search"
android:icon="#android:drawable/ic_menu_search"
android:orderInCategory="80"
android:title="#string/action_search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="always|collapseActionView"/>
</menu>
app: needs to be defined to have compatibility with android versions before 11.
SearchView needs to be support class v7.
== ListActivity / SherlockListActivity ==
The ListActivity is not supported ActionBarCompat, therefore the crucial functions of the ListActivity need to be implemented manual, which is rather simple:
private ListView mListView;
protected ListView getListView() {
if (mListView == null) {
mListView = (ListView) findViewById(android.R.id.list);
}
return mListView;
}
protected void setListAdapter(ListAdapter adapter) {
getListView().setAdapter(adapter);
}
protected ListAdapter getListAdapter() {
ListAdapter adapter = getListView().getAdapter();
if (adapter instanceof HeaderViewListAdapter) {
return ((HeaderViewListAdapter)adapter).getWrappedAdapter();
} else {
return adapter;
}
}
== Styles ==
A styled action bar can be achieved, see original google posting:
http://android-developers.blogspot.de/2013/08/actionbarcompat-and-io-2013-app-source.html
A styled searchView box is more difficult:
This works:
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
SearchView.SearchAutoComplete theTextArea = (SearchView.SearchAutoComplete) searchView.findViewById(R.id.search_src_text);
theTextArea.setTextColor(getResources().getColor(R.color.yourColor));
See these posts:
Changing the cursor color in SearchView without ActionBarSherlock
Change appcompat's SearchView text and hint color
== Example ==
Google Navigation Drawer with Action Bar Sherlock includes all original code (now aiming to support library) and formatting. Only some attributes had to be replaced with similar ones as they are only available from v11 onwards.
Download at: https://github.com/GunnarBs/NavigationDrawerWithActionBarCompat
== See also ==
http://android-developers.blogspot.de/2013/08/actionbarcompat-and-io-2013-app-source.html
http://developer.android.com/reference/android/support/v7/app/ActionBar.html
http://www.grokkingandroid.com/migrating-actionbarsherlock-actionbarcompat/
It is worth mentioning that there is no support version of the PreferenceActivity, so if you are using SherlockPreferenceActivity, you need to refactor to a support PreferenceFragment.
More info: How to add Action Bar from support library into PreferenceActivity?
Related
An error showing incompatible types Android widget toolbar cannot be converted in Java compiler while working on Android Studio.
Toolbar toolbar = (Toolbar)findViewById(R.id.toolBar);
toolbar.setTitle("GPS PRESENCE SYSTEM");
setSupportActionBar(toolbar);
Error: incompatible types: android.widget.Toolbar cannot be converted
to androidx.appcompat.widget.Toolbar
Try to replace this:
import android.widget.Toolbar;
With this:
import androidx.appcompat.widget.Toolbar;
By the way, if you are using androidx. Run it's migration process.
The android support libraries will not be supported in the future.
You can read about it here:
AndroidX
Migrating to AndroidX
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar); //No Problerm
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
we must import androidx.appcompat.widget.Toolbar;
don't import android.widget.Toolbar;
This error because your Toolbar created using android.widget.Toolbar .
But you are using androidX.
This also a same kind of error.
java.lang.ClassCastException: androidx.appcompat.widget.Toolbar cannot be cast to android.widget.Toolbar
To solve this kind of you can add these to lines in to your MainActivity.java file (to import).
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
Make sure to remove or comment out this android.widget.Toolbar .
Then again check for error like this. because sometime you may have to import more.
AndroidX is the new and improved support library
import androidx.appcompat.widget.Toolbar;
you can check more about from here here
Androidx's toolbar is designed for backwards compatibility while
android.widget.Toolbar
is the current plattform type
You are using androidx and Android both at the same time. That is throwing an error. Either use androidx or use android appcompat.
Change your activity toolbar import to:
import android.support.v7.widget.Toolbar;
You can invoke ActivityCompat#requireViewById which allows to omit the type cast and returns a #NonNull Toolbar reference:
Toolbar toolbar = ActivityCompat.requireViewById(this, R.id.toolbar);
setSupportActionBar(toolbar);
The title can be set on the #Nullable ActionBar reference returned by AppCompatActivity#getSupportActionBar:
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle("GPS PRESENCE SYSTEM");
}
simply delete
import android.widget.Toolbar;
and add
import androidx.appcompat.widget.Toolbar;
As reported by everyone else
import android.widget.Toolbar
is creating the issue.
Replace it with
import androidx.appcompat.widget.Toolbar
Mostly on android's recommendation we go for the tool and don't notice the android or androidx dependability.
That causes this error.
I have tried to clean up, rebuild and debug my code. I am making a simple quiz (GEO Quiz). I have a menu folder in my resources but there is nothing in it, but I still can get the error to go away. This is my first app.
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
public class QuizActivity extends Activity {
private Button tButton;
private Button fButton;
//private Question[] questions= new Question[5];
//private int qNum =0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
My layout and string.xml are correct thus far. Whenever i type in R. into the onCreateOptionsMenu class. There is no list or prompt that says menu on it.
You should have menu.xml in menu folder
if not, add the menu.xml file inside /res/menu/ folder, this is an example:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_settings"
android:orderInCategory="75"
android:title="my menu Item!"
app:showAsAction="never"/></menu>
Your menu resource folder does not have any xml file. the menu file should be on the menu resource folder.
The only solution that worked for my mac was to install MAMP. XAMPP did not work and locating files was confusing.
When entering commands in terminal all files had protection and contraints I could not do anything.
So MAMP is the best bet to solve this question. Make sure to use the php file in CLI interpeter.
I'm dipping my toes into Android Development by following along examples from this book. I am unable to get the example below to work, though. Instructions are: 1) New project named Dialog 2) Empty Activity 3) Paste/edit to look like the code below.
The message is that Studio can't resolve: R.id.toolbar, R.id.fab, R.menu, and R.id.action_settings.
I'm running Android Studio 3.1.3 on macOS High Sierra. My best guess is that that either the instructions are missing steps or since the book is ~2 years old Android Studio has changed behavior causing this example to break. I don't know enough about this development process to even know how to start to diagnose this.
In AndroidManifest.xml add this line to the activity block:
android:theme="#style/Theme.AppCompat.Dialog"
And this is the only code file to change (DialogActivity.java) for the project:
package com.example.sample.dialog;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
public class DialogActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dialog);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with an action",
Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_dialog, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_dialog.xml file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DialogActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
The reason you are getting those errors is because Java is looking for references in XML that have not been created. For example, it is looking for a reference called "R.id.fab" which was never created.
To fix this, you are going to have to go into the res folder and create the necessary files. Inside of the res -> layout -> "activity_dialog.xml" file, you will have to create a FAB in order to get rid of that error. You can copy/paste this code.
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"/>
Here, I create the necessary View in XML, and give it an id called fab so you can reference it in the java code. You will also need to create a menu folder and file, so to do that right click on the res folder, and go to "new Android Resource File". Set the file name to "menu" and the resource type should also be menu. Then when you hit "OK", you will see a new folder called menu, and inside of that a file called "menu.xml".
Inside that "menu.xml" file, you're going to have to create your menu options with an id of "action_settings". You can do that by using the code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/action_settings" android:title="Settings"/>
</menu>
Lastly, you can create your toolbar by right clicking on the layout folder and selecting new layout resource file. You can name it 'toolbar', and set the root element to android.support.v7.widget.Toolbar. This will generate the appropriate code for you, and you can edit it however you'd like. After that go back into the "activity_dialog.xml" file and use this code:
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
This should get rid of all 4 errors
Double check the id's in the R.layout.activity_dialog file. Android studio will output that message when the id that you are looking for is not found in the inflated layout.
EDIT:
You do not have a Toolbar declared in your XML file. When you want to search for a layout element to use in a Fragment or Activity, you use the id parameter you set in the XML file. If you forget to set the id or use the wrong id, it will tell you that the symbol cannot be resolved. There are too many items to add to your code, but follow the links below and you'll pick it up quickly enough. Let me know if you need more information. Also, CodePath is an excellent resource that I heavily relied on when I started learning Android development.
Look at this for a tutorial for adding a toolbar to a layout file and this for more miscellaneous information.
You have not gotten a reference to the view from the xml.
Get the reference from the xml for example if have a button defined in xml with an id of myBtn i would get the reference as Button button = findViewById(R.id.myBtn).
On the main menu, choose File. Invalidate Caches/Restart. The Invalidate Caches message appears informing you that the caches will be invalidated and rebuilt on the next start. Use buttons in the dialog to invalidate caches.
I am using custom ActionBar library in my Android App. there i want to show a searchView but can not find any solution, i m working in library that is
https://github.com/johannilsson/android-actionbar
This is a class
private class ExampleAction extends AbstractAction {
public ExampleAction() {
super(R.drawable.ic_title_export_default);
}
#Override
public void performAction(View view) {
Toast.makeText(OtherActivity.this, "Example action",
Toast.LENGTH_SHORT).show();
}
}
//use for signle action how to use for multiactions
ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
actionBar.addAction(new ExampleAction());
actually i found code for searchbar but it is in .cs format how to use this searchview
https://github.com/zleao/MonoDroid.ActionBar
Thanks bro & sis
Take a look at this answer.
According to this answer SearchView is available support library.
add dependency to build.gradle
compile 'com.android.support:appcompat-v7:22.0.0'
and make imports
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.SearchView;
According to this answer it worked on API 8 on emulator. For more details, check the link with the question and answer itself.
Hope it helps.
UPDATE
By adding this code
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:hmkcode="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_search"
android:orderInCategory="100"
hmkcode:showAsAction="always"
android:icon="#drawable/ic_action_search"
android:title="Search"/>
<item
android:id="#+id/action_copy"
android:orderInCategory="100"
hmkcode:showAsAction="always"
android:icon="#drawable/ic_content_copy"
android:title="Copy"/>
<item
android:id="#+id/action_share"
android:orderInCategory="100"
hmkcode:showAsAction="always"
android:icon="#drawable/ic_social_share"
android:title="Share"/>
you can achieve this:
You can customize items in the way you want. For more details see this example.
I am using ActionBarSherlock and Support Library v4. This is in a `SherlockFragmentActivity'.
I am getting a Nullpointer on line 269, referenced below. I have verified SearchView is null, not SearchManager. Though, menu is also null as well, I am not sure if that is normal? Important: It is ONLY null in my Android 4.0 and 4.1 tests. In 2.3, it works great!
Here is my SearchView Code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.menu, menu);
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView =
(SearchView) menu.findItem(R.id.menu_search).getActionView(); // line 269
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(true);
searchView.setSubmitButtonEnabled(true);
return true;
}
I have this as my menu item now.
<item
android:id="#+id/menu_search"
android:actionViewClass="com.actionbarsherlock.widget.SearchView"
android:icon="#android:drawable/ic_menu_search"
android:showAsAction="always"
android:title="search"/>
LogCat
FATAL EXCEPTION: main
java.lang.NullPointerException
at com.---.---.master.MainFragmentActivity
.setupSearchView(MainFragmentActivity.java:269)
at com.---.---.master.MainFragmentActivity.onCreateOptionsMenu(
MainFragmentActivity.java:258)
at android.support.v4.app.Watson.onCreatePanelMenu(Watson.java:45)
at com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(
ActionBarSherlock.java:559)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.preparePanel(
ActionBarSherlockCompat.java:479)
at com.actionbarsherlock.internal.ActionBarSherlockCompat
.dispatchInvalidateOptionsMenu(ActionBarSherlockCompat.java:272)
at com.actionbarsherlock.internal.ActionBarSherlockCompat$1.run(
ActionBarSherlockCompat.java:984)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(
ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
imports:
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.app.SherlockListFragment;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.widget.SearchView;
import android.app.SearchManager;
Again, I get Null Pointer in ONLY the 4.0 emulator and 4.1 device. App runs great in 2.3. At one time, pre-ActionBarSherlock, using the SAME code, except importing SearchView through the normal way (not Sherlock) it worked great in 4.0. I am trying to make my app backwards compatible and is broke the newer Android versions, but works great in the older.
EDIT: It was actually Null in 2.3 and Cast Issue in 4.0+ when the menu item had android:actionViewClass="android.app.SearchView"
Then I changed it to android:actionViewClass="com.actionbarsherlock.widget.SearchView"
and now FIXED in 2.3 and Null in 4.0+
UPDATE: I appeared to fix it with a hack:
I added a menu-v11 folder added a duplicate file of menu.xml with one item change only: android:actionViewClass="android.app.SearchView", otherwise it is identical to the other menu.xml file.
In Java, I did this:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.menu, menu);
MenuItem searchItem = menu.findItem(R.id.menu_search);
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
SearchView searchView = (SearchView) searchItem.getActionView();
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(true);
searchView.setSubmitButtonEnabled(true);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
setupNewSearchView(searchItem, searchManager);
}
return true;
}
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupNewSearchView(MenuItem searchItem,
SearchManager searchManager) {
android.widget.SearchView searchView =
(android.widget.SearchView) searchItem.getActionView();
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(true);
searchView.setSubmitButtonEnabled(true);
}
Well, it works, but I'm not putting it as an answer yet because it seems like hack way of doing it. Open to better ideas?
There is a problem with missing attrs for v14 (and v11?) in ActionBarSherlock (or ActionBarSherlock + HoloEverywhere + Theme.Sherlock.Light.DarkActionBar ?).
Simple solution and details in the issue thread…
You are trying to use two completely different classes, both named SearchView but in different packages. You cannot simply cast an object from one class into another class. com.actionbarsherlock.widget.Searchview is different than android.widget.SearchView. Therefore, searchView is null on line 269.
It would be relevant for us to see the imports from the top of your Java file.
Probably, the view referenced by R.id.menu_search is an android.widget.SearchView and your code expects it to be a com.actionbarsherlock.widget.Searchview.
Add a theme attribute to your manifest file under the tags of each of the activities that you plan to use an ActionBar. You can create your own custom theme or use one of the default offered by ActionBarSherlock.
<activity
android:name="com.example.MyActivityWithActionBar"
...
android:theme="#style/Theme.Sherlock.Light">
</activity>
More information on:
http://actionbarsherlock.com/theming.html
http://developer.android.com/guide/topics/ui/themes.html#ApplyATheme