Skip to content

Instantly share code, notes, and snippets.

@beta
Created October 6, 2016 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beta/c0f2a077773aaee329dadc3cbee8810c to your computer and use it in GitHub Desktop.
Save beta/c0f2a077773aaee329dadc3cbee8810c to your computer and use it in GitHub Desktop.
@Override
public void setCancelable(boolean cancelable) {
final Dialog dialog = getDialog();
View touchOutsideView = dialog.getWindow().getDecorView().findViewById(android.support.design.R.id.touch_outside);
View bottomSheetView = dialog.getWindow().getDecorView().findViewById(android.support.design.R.id.design_bottom_sheet);
if (cancelable) {
touchOutsideView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (dialog.isShowing()) {
dialog.cancel();
}
}
});
BottomSheetBehavior.from(bottomSheetView).setHideable(true);
} else {
touchOutsideView.setOnClickListener(null);
BottomSheetBehavior.from(bottomSheetView).setHideable(false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment