我在导航抽屉里面有一个Switch.Toggle只在敲击时发生。当我尝试滑动并切换开关时,导航抽屉会滑动。我该怎么办?
Switch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton v,
boolean isChecked) {
//switched
}
});
答案 0 :(得分:0)
在DrawerLayout上使用此代码:
settingsSwitch.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if((event.getAction() == MotionEvent.ACTION_MOVE) || (event.getAction() == MotionEvent.ACTION_DOWN))
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
else
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
return false;
}
});