Monday, December 31, 2012

Converting an Existing App to use ActionbarSherlock

I recently converted the Connexions app to use ActionbarSherlock.  This removed the dreaded menu button of shame when the device is running on Honeycomb and above.  It also had the side benefit of removing the menu button on Gingerbread and below.  It was fairly simple to migrate the app.  This post assumes you are able to add ActionbarSherlock as a library to your existing app.


All of the Activities were changed to extend ActionbarSherlock classes instead of the usual Android classes. Activity was changed to SherlockActivity, ListActivity to SherlockListActivity, etc.


Two Android menu classes were replaced wth the similar ActionbarSherlock classes

  • Menu
  • MenuItem

The menu XML files were modified to add the android:showAsAction attribute.  If you want the item to show up as a button on the Actionbar, set it to "ifRoom".  Otherwise, set it to "never" and the item will show up in the overflow drop down.


The Actionbar is accessed by calling getSupportActionbar().  Once you have a reference to the Actionbar, you can set the title by calling setTitle().

Progress Bar

The ProgressDialog and ActionbarSherlock did not play well together, so I removed the dialog and replaced it with the indeterminante progress spinner in the Actionbar.  To do this, I called setSupportProgressBarIndeterminateVisibility(true) in the onCreate() method and then set it to false when the Activity finished loading data.  You can see an example in almost all of the Activity classes

The code is available from our repository in GitHub. The Connexions for Android app is available in the Google Play Store or from the Connexions website.