fun Fragment.showBottomSheetDialog( @LayoutRes layout: Int, @IdRes textViewToSet: Int? = null, textToSet: String? = null, fullScreen: Boolean = true, expand: Boolean = true ) { val dialog = BottomSheetDialog(context!!) dialog.setOnShowListener { val bottomSheet: FrameLayout = dialog.findViewById(com.google.android.material.R.id.design_bottom_sheet) ?: return@setOnShowListener val bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet) if (fullScreen && bottomSheet.layoutParams != null) { showFullScreenBottomSheet(bottomSheet) } if (!expand) return@setOnShowListener bottomSheet.setBackgroundResource(android.R.color.transparent) expandBottomSheet(bottomSheetBehavior) } @SuppressLint("InflateParams") // dialog does not need a root view here val sheetView = layoutInflater.inflate(layout, null) textViewToSet?.also { sheetView.findViewById(it).text = textToSet } sheetView.findViewById(R.id.closeButton)?.setOnClickListener { dialog.dismiss() } dialog.setContentView(sheetView) dialog.show() } private fun showFullScreenBottomSheet(bottomSheet: FrameLayout) { val layoutParams = bottomSheet.layoutParams layoutParams.height = Resources.getSystem().displayMetrics.heightPixels bottomSheet.layoutParams = layoutParams } private fun expandBottomSheet(bottomSheetBehavior: BottomSheetBehavior) { bottomSheetBehavior.skipCollapsed = true bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED }