Home » Android » android – Using support action bar home enabled

android – Using support action bar home enabled

Posted by: admin June 15, 2020 Leave a comment


I’ve just modified our code to use the new SupportActionBar provided in the v7-appcompat library but when running the code on a Jellybean phone (presumably the same problem exists for Honeycomb and Ice Cream Sandwich) the home button doesn’t ever seem to be activated.

Calling getSupportActionBar().setHomeButtonEnabled(true); doesn’t seem to do what it says but works for Gingerbread phones.

If I replace it with getActionBar().setHomeButtonEnabled(true) it does work.

The theme that I use for v11+ is as follows:

<style name="MyTheme" parent="@style/Theme.AppCompat">
    <item name="android:windowActionBar">true</item>
    <item name="android:windowNoTitle">false</item>
    <item name="android:listViewStyle">@style/MyListView</item>
    <item name="android:actionBarStyle">@style/MyActionBarStyle</item>
    <item name="android:windowSoftInputMode">stateAlwaysHidden</item>
    <item name="android:buttonStyle">@style/MyButton</item>
    <item name="android:radioButtonStyle">@style/MyRadioButtonStyle</item>
    <item name="android:windowContentOverlay">@drawable/ab_solid_dove_grey</item>
    <item name="android:windowTitleSize">@dimen/action_bar_height</item>
    <item name="android:selectableItemBackground">@drawable/sel_standard_item</item>
    <item name="android:windowBackground">@drawable/default_bg</item>
    <item name="android:actionMenuTextAppearance">@style/MyActionBarText</item>
    <item name="android:actionMenuTextColor">@color/gallery</item>
    <item name="android:tabWidgetStyle">@style/MyTabWidget</item>

And the action bar style v11+ is defined:

<style name="MyActionBarStyle" parent="android:style/Widget.Holo.ActionBar">
    <item name="android:displayOptions">useLogo|showHome|showCustom</item>
    <item name="displayOptions">useLogo|showHome|showCustom</item>
    <item name="android:actionBarSize">@dimen/action_bar_height</item>
    <item name="android:icon">@drawable/ic_launcher</item>
    <item name="android:background">@android:color/transparent</item> <!-- Remove blue line from bottom of action bar -->

Anyone know why the home button is not getting enabled when on an Android version that supports action bar correctly.

=== UPDATE ===
I’ve just looked at the source code for the appcompat library and I’ve noticed the following in ActionBarImplBase which looks wrong to me:

 setHomeButtonEnabled(abp.enableHomeButtonByDefault() || homeAsUp);

This means that the home button will only be enabled if the Android version is less than ICS or if I’ve enabled the up indicator? – which I don’t want.

How to&Answers:

This one worked for me:

protected void onCreate(Bundle savedInstanceState) {
    // ... other stuff

public boolean onSupportNavigateUp(){
    // or call onBackPressed()
    return true;

The method onSupportNavigateUp() is called when you use the back button in the SupportActionBar.


Have you tried using all three of these (also try swapping for getSupportActionbar())?


Have you tried handling the button manually?

public boolean onOptionsItemSelected(int featureId, MenuItem item) {
     int itemId = item.getItemId();
     if(itemId == android.R.id.home){
         // Do stuff
     return true;


Try use Sherlock library for android devices such as Gingerbread cos android action bars is only supported from 3.0 upwards so the sherlock lock library gives you backward compatibility.

http://actionbarsherlock.com/ — download library here.

Then add this lines in your code.

ActionBar actionBar = getSupportActionBar();


This would help you to add a back home key in your action bar. It would also make your icon invisible if you dont want it to show.
But if you want your app icon show on all activity simply comment this line below



Now Please try this. Cause I was able to solve my own problem like this though it was on Sherlock. From your styles above I can see you did some customization to your themes. In my case I did some customization to my Sherlock theme and this was what gave me problem cos on android 4.0 and above my theme failed. so I simple added a piece of code that tells android to use the default Sherlock theme when it is running on android 4.0 and greater. So I suppose this would work for you. you tell android to use the default theme of v7-appcompat library on the version of android that is not working for you.

Code is below:

        } else {


In your case edit the theme to v7-appcompat library.

Please Mark as answer if it work for you. I believe it might be possible to customize the theme from the code for places were you are using this.


You can add an ActionBar to your activity when running on API level 7 or higher by extending ActionBarActivity class for your activity and setting the activity theme to Theme.AppCompat or a similar theme.