Set state of BottomSheetDialogFragment to expanded

前端 未结 14 867
有刺的猬
有刺的猬 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:44

    The easiest way I implemented is as below, Here we are finding android.support.design.R.id.design_bottom_sheet and setting bottom sheet state as EXPANDED.

    Without this, my bottom sheet was always stuck in the COLLAPSED state if view height is more than 0.5 of screen height and I have to manually scroll to view full bottom sheet.

    class BottomSheetDialogExpanded(context: Context) : BottomSheetDialog(context) {
    
        private lateinit var mBehavior: BottomSheetBehavior
    
        override fun setContentView(view: View) {
            super.setContentView(view)
            val bottomSheet = window.decorView.findViewById(android.support.design.R.id.design_bottom_sheet) as FrameLayout
            mBehavior = BottomSheetBehavior.from(bottomSheet)
            mBehavior.state = BottomSheetBehavior.STATE_EXPANDED
        }
    
        override fun onStart() {
            super.onStart()
            mBehavior.state = BottomSheetBehavior.STATE_EXPANDED
        }
    }
    

提交回复
热议问题