I want to use a seekbar in a Navigation Drawer
Basically I need to slide left and right to set the seekbar and, well, you guessed it, it slides the navigation drawer...<
Use DrawerLayout.setDrawerLockMode
instead of ViewParent.requestDisallowInterceptTouchEvent
.
In @dumazy answer requestDisallowInterceptTouchEvent
solves this issue but it also creates another.
While you are scrolling on navigation drawer, If you touch on SeekBar, OnSeekBarChangeListener
will trigger. So scrolling event will break and seekbar progress will start to change by moving your finger.
I modified the original answer a little bit to solve this issue using DrawerLockMode
:
mSeekBar.setOnTouchListener(new SeekBar.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow Drawer to intercept touch events.
// v.getParent().requestDisallowInterceptTouchEvent(true);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
// Allow Drawer to intercept touch events.
// v.getParent().requestDisallowInterceptTouchEvent(false);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED);
break;
}
// Handle SeekBar touch events.
v.onTouchEvent(event);
return true;
}
});