Open NavigationView only clicking on top-left icon but not with swype gesture

Viewed 912

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.

2 Answers

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