Created
November 15, 2021 19:07
-
-
Save yogeshpaliyal/982d567b87b9ec64581cd63624ac29ca to your computer and use it in GitHub Desktop.
Show full screen bottom sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | |
val dialog = super.onCreateDialog(savedInstanceState) | |
dialog.setOnShowListener { dialogInterface -> | |
dialog.window?.findViewById<View>(R.id.design_bottom_sheet)?.let { bottomSheetView -> | |
bottomSheetView.background = null | |
/* bottomSheetView.let { | |
BottomSheetBehavior.from(it).isFitToContents = true | |
BottomSheetBehavior.from(it).state = BottomSheetBehavior.STATE_EXPANDED | |
}*/ | |
val bottomSheetDialog = dialogInterface as BottomSheetDialog | |
setupFullHeight(bottomSheetDialog) | |
} | |
} | |
return dialog | |
} | |
private fun setupFullHeight(bottomSheetDialog: BottomSheetDialog) { | |
val bottomSheet: FrameLayout? = bottomSheetDialog.findViewById<View>(R.id.design_bottom_sheet) as FrameLayout? | |
val behavior: BottomSheetBehavior<*> = BottomSheetBehavior.from(bottomSheet!!) | |
val layoutParams: ViewGroup.LayoutParams = bottomSheet.layoutParams | |
val windowHeight = Resources.getSystem().displayMetrics.heightPixels | |
layoutParams.height = windowHeight | |
behavior.peekHeight = windowHeight | |
bottomSheet.layoutParams = layoutParams | |
behavior.state = BottomSheetBehavior.STATE_EXPANDED | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment