I have implemented bottomsheet behavior with NestedScrollView. And was wondering if it is possible to hide the bottomsheet view when touched outside.
Finally I was able to do this,
Used the following lines of code:
@Override public boolean dispatchTouchEvent(MotionEvent event){ if (event.getAction() == MotionEvent.ACTION_DOWN) { if (mBottomSheetBehavior.getState()==BottomSheetBehavior.STATE_EXPANDED) { Rect outRect = new Rect(); bottomSheet.getGlobalVisibleRect(outRect); if(!outRect.contains((int)event.getRawX(), (int)event.getRawY())) mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); } } return super.dispatchTouchEvent(event); }
Hope it save someone's whole day!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With