如何用手指禁用BottomSheetDialogFragment拖动?
我看到了类似的问题,但它们都是关于BottomSheet而不是BottomSheetDialogFragment的。
发布于 2020-08-12 11:13:19
在发布材料设计1.2.0之后,有一种更简单的方法来实现同样的目标。
从BottomSheetDialogFragment调用时
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val bottomSheetDialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
bottomSheetDialog.setOnShowListener {
val bottomSheet = bottomSheetDialog
.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)
if (bottomSheet != null) {
val behavior: BottomSheetBehavior<*> = BottomSheetBehavior.from(bottomSheet)
behavior.isDraggable = false
}
}
return bottomSheetDialog
}或造型:
<style name="SomeStyle" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
<item name="behavior_draggable">false</item>
</style>然后在对话框片段的onCreate中:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NORMAL, R.style.SomeStyle)
}发布于 2020-02-27 11:06:17
为时已晚,但值得分享。
behavior.setDraggable(false)这一行完成了任务。
发布于 2018-01-06 07:14:36
如果要禁用BottomSheetDialog拖动,请尝试设置setCancelable(false)。
https://stackoverflow.com/questions/46861306
复制相似问题