How to disable BottomSheetDialogFragment
dragging by finger?
I saw similar questions, but they\'re all about BottomSheet
not BottomSheetD
There is simpler way of achieving the same after material design 1.2.0 was released.
https://developer.android.com/reference/com/google/android/material/bottomsheet/BottomSheetBehavior#setdraggable
When calling from BottomSheetDialogFragment
:
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val bottomSheetDialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
bottomSheetDialog.setOnShowListener {
val bottomSheet = bottomSheetDialog
.findViewById(com.google.android.material.R.id.design_bottom_sheet)
if (bottomSheet != null) {
val behavior: BottomSheetBehavior<*> = BottomSheetBehavior.from(bottomSheet)
behavior.isDraggable = false
}
}
return bottomSheetDialog
}
Or with styling:
And then in onCreate
of your dialog fragment:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NORMAL, R.style.SomeStyle)
}