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

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

Posted by: admin April 23, 2020 Leave a comment

Questions:

I am having difficulties trying to remove the back/home button from the action bar.

 getActionBar().setDisplayShowHomeEnabled(false);   //disable back button
 getActionBar().setHomeButtonEnabled(false);

In a older android phone, the back button is removed with these two code lines. However with the nexus 4, the back button still appears but is just disabled. Also I am just adding a menu item on the right that behaves like the back/home button replacing the back/home button. What am I missing?

How to&Answers:

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

Answer:

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

Answer:

ElectronicGeeks answer is correct.

For API lower than 11, Use:

getSupportActionBar().setDisplayHomeAsUpEnabled(false);

Answer:

To control the up affordance, use setDisplayHomeAsUpEnabled().

Answer:

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.

Answer:

You can use this code :

toggle.setDrawerIndicatorEnabled(false);

Works great for me.

Answer:

This code work for me

For remove navigation bar
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

For remove status bar
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);

ฺBut above code, it show again when you touch on screen, so if you want static state, combine this code.

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE);

Answer:

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);