How to disable BottomSheetDialogFragment
dragging by finger?
I saw similar questions, but they\'re all about BottomSheet
not BottomSheetD
This is the Kotlin version of azizbekian's answer since someone asked about using data binding
@SuppressLint("RestrictedApi")
override fun setupDialog(d: Dialog?, style: Int) {
super.setupDialog(d, style)
dialogExampleBinding = DataBindingUtil
.inflate(LayoutInflater.from(context), R.layout.dialogExample, null, false) //This is for data binding only
d?.setContentView(R.layout.dialogExample)
val myDialog:BottomSheetDialog = d as BottomSheetDialog
val dField = myDialog.javaClass.getDeclaredField("behavior") //This is the correct name of the variable in the BottomSheetDialog class
dField.isAccessible = true
val behavior = dField.get(d) as BottomSheetBehavior<*>
behavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, newState: Int) {
if (newState == BottomSheetBehavior.STATE_DRAGGING) {
behavior.state = BottomSheetBehavior.STATE_EXPANDED
}
}
override fun onSlide(bottomSheet: View, slideOffset: Float) {}
})
}