BottomSheetDialogFragment 自定義高度 顯示完全

BottomSheetDialogFragment 默認的顯示方式,是有一小段是要自己滑上來的,那麼如何讓他顯示完全呢。。。直接上代碼吧,原理啥的大家也估計不愛看。。。網上大多數的代碼都是有問題的,跑不了的。。。直接在onstart裏面加上下面的代碼就OK了

 

override fun onStart() {
        super.onStart()
        val dialog = dialog as BottomSheetDialog
        if (dialog != null) {
            val bottomSheet = dialog.delegate.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet)
            bottomSheet!!.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT  //自定義高度
        }
        val view = view
        view!!.post {
            val parent = view.parent as View
            val params = parent.layoutParams as CoordinatorLayout.LayoutParams
            val behavior = params.behavior
            val bottomSheetBehavior = behavior as BottomSheetBehavior<*>?
            bottomSheetBehavior!!.peekHeight = view.measuredHeight
        }
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章