Set state of BottomSheetDialogFragment to expanded

前端 未结 14 830
有刺的猬
有刺的猬 2020-11-30 19:11

How do you set the state of a fragment extending BottomSheetDialogFragment to expanded using BottomSheetBehavior#setState(STATE_EXPANDED) using the

14条回答
  •  粉色の甜心
    2020-11-30 19:31

    In your Kotlin BottomSheetDialogFragment class, override onCreateDialog as below

    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
                    )
                val behavior = BottomSheetBehavior.from(bottomSheet!!)
                behavior.skipCollapsed = true
                behavior.state = BottomSheetBehavior.STATE_EXPANDED
            }
            return bottomSheetDialog
        }
    

提交回复
热议问题