1

On click of button, screen presents a BottomSheetDialogFragment but when I touch outside on the window, it gets dismissed.

Is there a way to disable it like we do for dialog using api setCanceledOnTouchOutside. I have tried using setting up setCanceledOnTouchOutside = false in onCreateDialog method of my class (which extends BottomSheetDialogFragment) but no luck.

Dhaval Solanki
  • 4,332
  • 1
  • 22
  • 36
vijay_t
  • 676
  • 5
  • 13
  • https://stackoverflow.com/questions/42154321/prevent-dismissal-of-bottomsheetdialogfragment-on-touch-outside and https://medium.com/@betakuang/make-your-bottomsheetdialog-noncancelable-e50a070cdf07 – Pankaj Kumar Jun 14 '19 at 06:11

3 Answers3

0

I suggest set false in setCancelable, it will work for you

BottomSheetDialogFragment btmSheetDialog = new BottomSheetDialogFragment();
btmSheetDialog.setCancelable(false);
btmSheetDialog.show(getChildFragmentManager(), btmSheetDialog.getTag());
Dhaval Solanki
  • 4,332
  • 1
  • 22
  • 36
0

you have to do like below

val bottomSheetDialogFragment = BottomSheetDialogFragment()
        bottomSheetDialogFragment.isCancelable = false
        bottomSheetDialogFragment.show(supportFragmentManager, bottomSheetDialogFragment.tag)
Mehul Kabaria
  • 6,022
  • 4
  • 24
  • 46
0

Based on DialogFragment document

https://developer.android.com/reference/android/support/v4/app/DialogFragment.html#setCancelable(boolean)

Control whether the shown Dialog is cancelable. Use this instead of directly calling Dialog.setCancelable(boolean), because DialogFragment needs to change its behavior based on this.

Params:
cancelable – If true, the dialog is cancelable. The default is true.

You may try this :

In Kotlin

   val switchAccountBottomSheet = SwitchAccountBottomSheet()
   switchAccountBottomSheet.isCancelable = false
   switchAccountBottomSheet.show(getActivity().getSupportFragmentManager(), SwitchAccountBottomSheet.class.getName());

In Java

SwitchAccountBottomSheet mSwitchAccountBottomSheet = new SwitchAccountBottomSheet();
mSwitchAccountBottomSheet.setCancelable(false);
mSwitchAccountBottomSheet.show(getActivity().getSupportFragmentManager(), SwitchAccountBottomSheet.class.getName());
Mayur Patel
  • 2,214
  • 9
  • 27