android: how to remove the back/home button in the action bar

If you're on API level 14 or above and are not using ActionbarSherlock, this code in onCreateOptionsMenu will disable the up button, remove the left caret, and remove the icon:

ActionBar actionBar = getActionBar();
if (actionBar != null) {
    actionBar.setHomeButtonEnabled(false); // disable the button
    actionBar.setDisplayHomeAsUpEnabled(false); // remove the left caret
    actionBar.setDisplayShowHomeEnabled(false); // remove the icon
}

source: https://stackoverflow.com/a/24967862/2887103


Use getActionBar().setDisplayHomeAsUpEnabled(false) to remove the home button from the action bar.


ElectronicGeeks answer is correct.

For API lower than 11, Use:

getSupportActionBar().setDisplayHomeAsUpEnabled(false);


To control the up affordance, use setDisplayHomeAsUpEnabled().

Tags:

Android