I am having difficulties trying to remove the back/home button from the action bar.
getActionBar().setDisplayShowHomeEnabled(false); //disable back button
ElectronicGeeks answer is correct.
For API lower than 11, Use:
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
None of the suggested solutions works for me.
But this one does:
// Hide the back button
mActionBar.setHomeAsUpIndicator(null);
It is a kind of a hack (last resort solution), though, so showing the action bar again means setting its icon back again.
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
This worked for me :)
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(false);
In case where you have used toolbar as Action bar:-
Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar);
Use the below code to hide navigation button:-
toolbar.setNavigationIcon(null);
Use getActionBar().setDisplayHomeAsUpEnabled(false)
to remove the home button from the action bar.