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,589
  • 1
  • 23
  • 39
vijay_t
  • 776
  • 6
  • 14
  • 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,589
  • 1
  • 23
  • 39
0

you have to do like below

val bottomSheetDialogFragment = BottomSheetDialogFragment()
        bottomSheetDialogFragment.isCancelable = false
        bottomSheetDialogFragment.show(supportFragmentManager, bottomSheetDialogFragment.tag)
Mehul Kabaria
  • 6,404
  • 4
  • 25
  • 50
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,300
  • 11
  • 30