Home » Android » android – Problems implementing tabs in ActionBarSherlock 4

android – Problems implementing tabs in ActionBarSherlock 4

Posted by: admin May 14, 2020 Leave a comment


I really want to get this to work, but I feel like I’ve been floundering about for hours. I’m starting up a new app and want to try to follow the UI guidelines as close as possible, which for anything below ice-cream sandwich seems to mean I need to use ActionBarSherlock. Looking at the example here it looks like it should be straightforward.

I try to implement it and it doesn’t work because FragmentActivity does not have a getSupportActionBar() method.

Taking a look at the demo app and it seems they don’t use FragmentActivity, they use SherlockActivity. Well, SherlockActivity does have a getSupportActionBar() method, so that’s promising. Continuing on with the example for a while…

Okay, now it seems the com.actionbarsherlock.app.ActionBar.TabListener doesn’t pass FragmentTransaction to its events? Not only that, but the SherlockActivity doesn’t have a getSupportFragmentManager() method…

Am I (hopefully) just doing something completely wrong? How do I keep encountering all these issues that no one else is? I feel like I’m going nuts here. The only potentially related issue I’ve found is here and it’s not very useful.

How to&Answers:

You need to extend from SherlockFragmentActivity instead of only SherlockActivity or SherlockFragment. This way you will get access to ABS and the Fragment Support.


I ran into a similar problem trying to get a map view and fragments to work with actionbarsherlock. See my post on the mailing list.

The solution I came up with was to get the sources for the compatibility library and modify the FragmentActivity to extend a SherlockActivity instead of a standard android Activity.

Then you’ll need to compile the sources for the support library along with your app(in some fashion).

In my case I went an additional step to modify the SherlockActivity to extend MapActivity, but since you didn’t mention maps, you wouldn’t need to do that.

There may be other solutions, but this at least got things to work for me.

I would recommend the mailing list as this project seems to be changing frequently.


Try to use extend from com.actionbarsherlock.app.SherlockFragmentActivity and take a look at https://github.com/inazaruk/examples/tree/master/MapFragmentExample to see how to use a Map with Fragments.