155

What is the difference between ActionBarSherlock and Action Bar Compatibility

Fews days ago Google just released the ActionBar Compatibility that make me so confused. Is that the Action Bar Compatibility works same as the ActionBarSherlock and is the coding same?

Example : Does app icon to navigate "up" or ActionBar.Tab supported in Action Bar Compatibility ?

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
xDragonZ
  • 12,502
  • 6
  • 37
  • 52
  • 12
    FYI I wrote a blog post about this for Square's eng blog: http://corner.squareup.com/2012/05/actionbarsherlock-as-a-base.html – Jake Wharton Jun 22 '12 at 01:16
  • 3
    http://www.youtube.com/watch?feature=player_detailpage&v=Jl3-lzlzOJI#t=224 This is what Google thinks of ActionBarSherlock vs ActionBarCompact – Rolf ツ Sep 27 '13 at 12:33

7 Answers7

113

ActionBarSherlock vs ActionBarCompat:

I Just want to put few code difference between ActionBarSherlock vs ActionBarCompat Lib

 ActionBarSherlock vs ActionBarCompat **strong text**

We can migrate some apps from ActionBarSherlock to ActionBarCompat:

steps:

  1. Import AppCompat project.

  2. Replace SherlockFragmentActivity with ActionBarActivity.

  3. Replace SherlockFragment with Fragment.

  4. Change Menu, MenuItem and getSupportMenuInflater() references. Modify the way you get Action Views.

    mSearchView = (SearchView)MenuItemCompat.getActionView(mSearchItem)

  5. Modify your Themes and Styles.

For more info, please refer this slides by +NickButcher (Google)

enter image description here

Thanks to Sources: http://gmariotti.blogspot.in/2013/07/actionbarsherlock-vs-actionbarcompat.html http://antonioleiva.com/actionbarcompat-migrating-actionbarsherlock/

Don't forget to read this developer.android for more about ABC!

Note: Setting it up for unit tests the same way as ABS is unfortunately not possible with the support library.

Output:

enter image description here

Credits: Gabriele Mariotti

LOG_TAG
  • 19,894
  • 12
  • 72
  • 105
60

ActionBarSherlock gives your application an action bar regardless* of what version of the android API your app is being run on. Action Bar Compatibility gives you the action bar only if the device that you're running on is API level 3.0 or above.

*Note that if the device you're running on isn't 3.0 or above, ActionBarSherlock is going to use it's own custom implementation of the action bar, not a native one.

--EDIT--

It appears things have changed and there is actually no difference between ActionBarSherlock and the Action Bar Compatibility anymore. Please read the comments below for details.

--EDIT--

After having used both now, I can say that I actually prefer ActionBarSherlock to Action Bar Compatibility. ActionBarSherlock is really easy and nice to use.

--EDIT-- As LOG_TAG mentioned, there is now support for the action bar in the Android Support Library. I haven't had a chance to use it yet, but I would imagine that's the best one to use.

LOG_TAG
  • 19,894
  • 12
  • 72
  • 105
Kurtis Nusbaum
  • 30,445
  • 13
  • 78
  • 102
  • I just tested on 2.3.5 device , the Action Bar Compatibility also works on pre-API 11 devices. Does the Action Bar Compatibility just modify the activity title bar to make it have a actionbar design look ? – xDragonZ Oct 21 '11 at 03:21
  • No, it's not modifiying the title bar. According to the website it "will automatically wrap a custom implementation around your layouts". – Kurtis Nusbaum Oct 21 '11 at 03:24
  • Ok, so the ActionBar.Tab , setDisplayHomeAsUpEnabled , getActionBar() and others function that related to actionbar will not work on "Action Bar Compatibility" because it just wrap a custom implementation around the layouts ? – xDragonZ Oct 21 '11 at 03:28
  • No, they'll work as long as the device it's being run on api 3 or up. – Kurtis Nusbaum Oct 21 '11 at 03:31
  • Ok, thanks I think I understand now. So if I want to use ActionBar.Tab and related function on pre-API 11 devices I have to use ActionBarSherlock right? – xDragonZ Oct 21 '11 at 03:34
  • Action Bar Compatibility gives you the action bar only if the device that you're running on is API level 3.0 or above. = i guess this is wrong they can be used on pre-3.0. – Mikey Dec 09 '11 at 14:36
  • @mikedroid I don't understand you're comment – Kurtis Nusbaum Dec 09 '11 at 17:45
  • I don't think this is actually the case. According to http://developer.android.com/resources/samples/ActionBarCompat/index.html, ActionBarCompatibility uses the built-in ActionBar on 3.0 and up, and a custom implementation pre-3.0, just like Sherlock does. That page even has a screenshot of ActionBarCompatibility's custom implementation running on a Gingerbread device. So then it seems both frameworks can provide a "faux action bar" on pre-3.0 devices, and the differences in fact lie elsewhere. – Victor Dec 26 '11 at 02:58
  • 1
    @Anidamo Thanks for the heads up. I might be going insane, but I could swear that at one point, the version in the android compatibility pack didn't give you one if your pre-3.0. I've modified my answer. – Kurtis Nusbaum Dec 26 '11 at 03:44
  • 1
    I reluctant to believe that there is no difference between both. What about ease of usage? What about tabs? What about landscape vs. portrait? Voting down. – AlikElzin-kilaka Feb 22 '12 at 09:47
  • 35
    Also, the answer is totally wrong - the purpose of the compatibility example is to support pre-3.0 devices. – AlikElzin-kilaka Feb 22 '12 at 10:00
  • So those with experience with this: Do you find the ActionBarCompatibility or ActionBarSherlock to be easier to implement? I was planning on using ABS and Jake's ViewPagerIndicator in order to give my apps that 4.0 look. – TJ Biddle Apr 16 '12 at 13:19
  • Edit is wrong there is a lot of difference between both of them – Necronet May 15 '12 at 12:12
  • 8
    Google released a new backward-compatible Action Bar implementation called ActionBarCompat that's part of the Support Library r18. The ActionBarCompat APIs let you build the essential Action Bar design pattern into your app, with broad compatibility back to Android 2.1. – LOG_TAG Aug 12 '13 at 08:51
  • 3
    Following link tells you `why` and `how` to use the new ActionBarCompat API, http://android-developers.blogspot.in/2013/08/actionbarcompat-and-io-2013-app-source.html – VenoM Aug 14 '13 at 12:23
  • ActionBar compatibility does not have support for adding ActionBar on a prefernceActivity, ActionBarSherlock does have this support. So they are not the same atleast as of now. – Ahmed Oct 26 '13 at 20:24
  • 2
    Just to add, for those who think they may want Chromecast integration in their app, I'd highly recommend using appcompat library. The MediaRouter APIs necessary for Chromecast integration depends on appcompat; ActionBarSherlock cannot be used. – b.lyte Oct 28 '13 at 20:13
  • It might be a good idea to use ActionBarCompat since future development for ActionBarCompat has been stopped https://plus.google.com/+JakeWharton/posts/F3HkWY9J8fK – Mark Pazon Feb 08 '14 at 21:14
41

Just completing what @Kurtis Nusbaum with a pratical example.

UPDATE: as @rudy-s said, with newest android support library (api 18), I saw they already have built-in support for actionbar (called ActionBarCompat class).

I built two simple applications to show the visual difference between ActionBarSherlock and ActionBar Compatibility. See the comparatives images:

App using compatibility library

App using sherlock library

Now the appearance when the menu button is pressed:

App using compatibility on menu pressed

App using sherlock on menu pressed


As you can see, the images just enforce what was said. Action Bar Compatibility gives you the action bar only if the device that you're running on is API level 3.0 or above. While Sherlock is more general.

Below you can see the application source.

The menu xml file is the same:

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

<item
    android:id="@+id/action_1"
    android:orderInCategory="100"
    android:showAsAction="always"
    android:title="@string/action1"/>

<item
    android:id="@+id/action_2"
    android:orderInCategory="100"
    android:showAsAction="ifRoom"
    android:title="@string/action2"/>

<item
    android:id="@+id/action_3"
    android:orderInCategory="100"
    android:showAsAction="ifRoom"
    android:title="@string/action3"/>

<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/action_settings"/>

</menu>

Compatibility's activity:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
     }

     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
     }
}

Sherlock's activity:

public class MainActivity extends SherlockActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
        getSupportMenuInflater().inflate(R.menu.main, menu);
        return super.onCreateOptionsMenu(menu);
    }

}

An additional config was necessary on sherlock app:

<style name="AppBaseTheme" parent="Theme.Sherlock.Light.DarkActionBar">

UPDATE: as @rudy-s said, with newest android support library (api 18), I saw they already have built-in support for actionbar (called ActionBarCompat class).

Bruno Mateus
  • 1,727
  • 18
  • 25
  • 5
    Actually, this is not entirely correct. The Compat library can, and does give you an ActionBar implementation on Gingerbread. This app for example gives you an AB on GB and does not use Sherlock but Compat. https://play.google.com/store/apps/details?id=uk.co.mxdata.rootle – Hamid May 17 '13 at 10:02
  • There is no need, if you pull that actionbarcompat sample out (for example out of the android-17 sdk) and build it in ADT, it will run on a GB device with an ActionBar. I just tested it myself to confirm on a Desire HD with 2.3.5. – Hamid May 17 '13 at 15:38
  • Ok, I got it. However, ActionBarSherlock provides more features, isn't it? – Bruno Mateus May 17 '13 at 17:17
  • 2
    With newest android support library (api 18), I saw they already have built-in support for actionbar (called ActionBarCompat class). – rudy s Jul 25 '13 at 14:13
  • GingerBEARD? Love it. – Carlos P Jun 25 '14 at 16:18
39

Actionbar Sherlock is far more advanced and far more ambitious than the simple Actionbar compatibility project.

The Action bar compatibility can be considered a "sample" or a good starting point if you only want to smack an Action Bar on top of your app.

ActionBarSherlock builds on the compatibility library, and gives you (like the action bar compatibility sample) an Action Bar on pre-3.0 devices. In addition it has extra features not present in the ActionBar Compat code. This includes features like, but not limited to

  • setNavigationMode (for Tabs and spinners in the action bar)
  • Dialog Fragments
  • Contextual Action Bar (CAB) a menu that takes over the action bar, used for example for multi select (http://developer.android.com/design/patterns/new-4-0.html) This is a ICS feature (!) For this, an implementation of the ActionMode class (introduced in API level 11) had to be introduced into the ActionbarSherlock library
  • Fragment and FragmentActivity implementations - because fragments can implement the onCreateOptions menu, we need to make sure that the SupportMenuInflater is used.
  • Two themes not very unlike Holo.Dark and Holo.Light (Theme.Sherlock, Theme.Sherlock.Light)
  • The ICS feature "split action bar"

The only downside I see in using ActionbarSherlock is that you lock yourself in to that library. If for some reason it will die out in the near future, you'll have to maintain it youself (for example if no Jellybean implementation comes along). This is a hassle (not a huge problem) since all your fragments extends SherlockFragemnt and all your Activities. SherlockActivity.

Glenn Bech
  • 6,103
  • 4
  • 39
  • 56
  • Am I missing something? It seems that multi select is NOT support in ABS – jiduvah Nov 22 '12 at 17:31
  • 1
    Sorry for the delay. Multi select is not by itself supported by ABS. But, you can implement Multiselect by using the ABS "ActionMode", as ABS has its own implementations of the ActionMode classes. When going into "multi select mode", You would set the ListView's choice mode to CHOICE_MODE_MULTIPLE, and invoke ActionMode by calling getSherlockActivity().startActionMode(callback) – Glenn Bech Feb 10 '13 at 10:41
26

Well @Jake implementation goes way further than what the Actionbar compat, to be more precise Actionbar Compat is just a basic example on how can you support all aplication with a pseudo-actionbar for releases prior from Honeycomb (API 13). Although their target is the same cross compatible actionbar, they have diferent approach.

ActionbarCompat Aproach

This implementation make no use of the Compatibility Android support library instead it create a base class called ActionBarActivity create a single instance of a Helper this helper act as factory itself that returns diferent implementation for the three segment of APIS, it returns

The most interesting part is in the ActionbarBaseHelper, because it has the most important code, I suggest you understand this class and you will get the whole example.

Action Bar Sherlock

Well this is tricky firstable because, I'm not the author maybe Jake can explained further this, but I'll give it a try.

Just as the compat Sherlock make diferent implementation but one is for "Compat" and the other is Native. It force you to extends either from SherlockActivity or from SherlockFragmentActivity, because this two base classes have the method for dispatching the ActionBar.

This is a large and complex project, that cannot be explained in a single post. Suggest you dig around Sherlock Github repo grab a look and as Jeff Atwood says

enter image description here

Necronet
  • 6,704
  • 9
  • 49
  • 89
10
  • I strongly believe that you should use ActionBarCompat for all new projects that want to support older devices.

  • It also might make sense to migrate existing projects. So read on to learn why you should migrate or use ActionBarCompat right away and how to migrate existing projects.

Why you should prefer ActionBarCompat over ActionBarSherlock?

There are many reasons why you should prefer ActionbarCompat over ActionbarSherlock.

  1. First of all this project is by Google, is part of the Support Library and thus likely will support new Action Bar related stuff at the same time Google releases them with stock Android.

  2. Another good reason is that it supports the Navigation Drawer pattern right out of the box, while ActionBarSherlock does not. Thus if you want to add this drawer to an existing project/app you should migrate.

  3. The last and Important is, that the creator of ActionBarSherlock, Jake Wharton, announced on Google+ that further development of ActionBarSherlock has been stopped. ActionBarSherlock 4.4 is the last release and might get bug fixes – but there won’t be any new features: So if new functionality is included in actionbar you may not keep up to it with actionbarsherlock.

Stephen
  • 9,899
  • 16
  • 90
  • 137
7

Maybe we should update the answer because google published offical Actionbar support since API18?

block below is from offical blog about these two libraries:

If you’re using a third-party solution (such as ActionBarSherlock), there are a few reasons to consider upgrading:

  • Can be kept updated as the Action Bar API evolves.
  • Integrated Ancestral Navigation support.
  • Use of framework Menu and MenuItem classes.
  • Continue to use the Support Library's Fragment class.
  • Integrated support for ActionBarDrawerToggle for use with DrawerLayout.
  • Backport of PopupMenu.

ActionBarSherlock is a solid and well-tested library which has served developers very well for a long time. If you are already using it and do not currently require any of the above then there is no need to migrate.

Community
  • 1
  • 1
ruidge
  • 1,149
  • 1
  • 15
  • 14