You can use this method to lock or unlock a drawer: DrawerLayout.setDrawerLockMode(...) . (There are also two other versions of this method to specify the lock mode for specific mailboxes.) To lock, use DrawerLayout.LOCK_MODE_LOCKED_CLOSED ; to unlock, use DrawerLayout.LOCK_MODE_UNLOCKED .
If you are using an ActionBarDrawerToggle, you need to add additional code to prevent the box from opening when you click on the ActionBarDrawerToggle if you lock the box.
@Override public boolean onOptionsItemSelected(MenuItem item) { // check lock mode before passing to ActionBarDrawerToggle // I assume your drawer is on the left; if not, use Gravity.RIGHT int lockMode = mDrawer.getDrawerLockMode(Gravity.LEFT); if (lockMode == DrawerLayout.LOCK_MODE_UNLOCKED && mDrawerToggle.onOptionsItemSelected(item)) { return true; } // Handle your other action bar items... return super.onOptionsItemSelected(item); }
source share