본문 바로가기

컴퓨터 공학/Android

BottomSheetDialogFragment를 Fullscreen으로 보이기

아래와 같이 BottomSheetDialogFragment의 onStart() 함수를 override하여 BottomSheetDialogFragment.show()와 동시에 Fullscreen 상태로 보이도록 만들 수 있다.

    override fun onStart() {
        super.onStart()

        if (dialog != null) {
            val bottomSheet: View = dialog!!.findViewById(R.id.design_bottom_sheet)
            bottomSheet.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
        }

        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
            parent.setBackgroundColor(Color.TRANSPARENT)
        }
    }