0

How to disable the ActionBar button that opens navigation drawer?

I use the code below to disable opening the navigation drawer using swipe, but its action bar button (at Top/Left) still active and can be used to open the navigation drawer.

 DrawerLayout navigationDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
 navigationDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
Ashraf Alshahawy
  • 1,139
  • 1
  • 14
  • 38

3 Answers3

3

Try This i think it Will help you

actionBar.setDisplayHomeAsUpEnabled(false);

or you can use this

getActionBar().setDisplayHomeAsUpEnabled(false);
Dilavar Malek
  • 1,157
  • 11
  • 18
  • Thank you, that worked well, it hides the button in the action bar, but what if I want to override this button rather than hiding it, I mean, to change its icon (To be as back button) and rather than opening the drawer I use it to be as back button, is it possible? – Ashraf Alshahawy Apr 03 '15 at 11:44
  • Thanks, by any chance do you have any article talking about this. – Ashraf Alshahawy Apr 03 '15 at 19:56
1

Use this:

getActionBar().setHomeButtonEnabled(false);
Avishek Das
  • 661
  • 1
  • 6
  • 20
0

You should use setNavigationOnClickListener() on toolbar to avoid Nav Drawer from opening.

toolbar.setNavigationOnClickListener(new View.OnClickListener() {
     @Override
         public void onClick(View view) {
         // your code.
     }
});

Nav drawer will open just by swiping, and not by clicking on the menu item button.

Tincho825
  • 829
  • 1
  • 13
  • 15