3

I am implementing the navigation view in my app.

Actually, I can open it both clicking on "hamburger" icon (in my toolbar) and swypeing from left to right.

I want to open it only through the icon in my toolbar disabling the swype. Is it possible to do that?

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, sToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);

toggle.syncState();

EDIT

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); // HERE
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, sToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);

toggle.syncState();

If I use the code above, where I used DrawerLayout.LOCK_MODE_LOCKED_CLOSED, I disable both icon and swype.

eldivino87
  • 1,425
  • 1
  • 17
  • 30
  • Possible duplicate of [disable the swipe gesture that opens the navigation drawer in android](http://stackoverflow.com/questions/17051104/disable-the-swipe-gesture-that-opens-the-navigation-drawer-in-android) – Ajinkya Mar 14 '16 at 12:37
  • No, this is not a duplicate. It's asking to keep hamburger icon enabled and disable left swipe gesture. I had the same question. – Heisenberg Jun 29 '16 at 11:18
  • and how did you finally solve your problem? – sepehr Aug 14 '16 at 06:33
  • did you find solution for this ? – pallavi Oct 05 '16 at 09:27

2 Answers2

1

This works for my case

Lock it:

drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

And unlock it :

drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);

Hope to help!

Kristiyan Varbanov
  • 2,439
  • 2
  • 17
  • 37
1

To make only the click work on the hamburger icon and not the swipe, i did the following,

DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, mDrawerLayout, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
mDrawerLayout.addDrawerListener(toggle);
toggle.syncState();

mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
            mDrawerLayout.openDrawer(GravityCompat.START);
        }
    });
pallavi
  • 432
  • 3
  • 14