2014-02-06 56 views

回答

1

use mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

+0

當我使用它時,我禁用滑動手勢打開和關閉。有一種方法可以禁用只是打開? – user3249186

+0

不是真的,這將禁用用戶的所有操作,您不能選擇哪個 – BradR

1

這應該做的伎倆

如果你想防止通過刷卡可拉開抽屜,正常關閉,這是天雷
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); 
+0

當我使用它時,我禁用滑動手勢打開和關閉。 有一種方法可以禁用只是打開? – user3249186

0

 // Drawer Layout 
     final DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 
     ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,R.string.hello_world, R.string.action_settings){ 

      @Override 
      /** Called when a drawer has settled in a completely closed state. */ 
      public void onDrawerClosed(View view) { 
       Log.d("here","close"); 
       drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); 
      } 
      @Override 
      /** Called when a drawer has settled in a completely open state. */ 
      public void onDrawerOpened(View drawerView) { 
       Log.d("here","open"); 
       drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); 
      } 
     }; 
     drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); 
     toggle.setDrawerIndicatorEnabled(true); 
     drawerLayout.setDrawerListener(toggle); 
     toggle.syncState(); 

棘手的部分是,當它關閉時應鎖定抽屜,並在抽屜打開時再次解鎖!