David Caunt

Mobile Software Engineer

Subscribe to my RSS feed

Android Gotcha – Action Bar Home Icon Doesn’t Work

January 21st, 2012

Hopefully by now you’re using the Action Bar in your applications – it’s pretty much mandatory unless you’re making a game or something unusual. I recommend using the excellent ActionBarSherlock to deal with pre-Honeycomb platforms.

Jumping straight in with ActionBarSherlock can cause you to skip over the official ActionBar docs, leading to confusion over implementation details. On older devices the ActionBar home icon works fine and yet, on ICS, the button doesn’t work!

For packages targetting API level 14 onwards, you need to explicitly enable the home button by calling setHomeButtonEnabled()

In your onCreate, add the following:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    getActionBar().setHomeButtonEnabled(true);
}

The moral of the story is to always read the official docs and be aware of the differences between a native and compatibility library ActionBar implementation.

 

Leave a Reply

You may wrap code in <code> tags or use <pre lang="php">code</pre> for full highlighting.

Top