Problem
I need to use BottomSheetDialog (com.google.android.material.bottomsheet) for my apps, but it didn't work as i expected, Bottom Sheet Appear cut when it expanded.
My Implementation
inline fun <T : ViewBinding> Context.makeBottomSheetDialog(
crossinline bindingInflater: (LayoutInflater) -> T,
isCancelable: Boolean = true,
isHideable: Boolean = true,
isFitContent: Boolean = true,
peekHeight: Int? = null,
onDismissListener: DialogInterface.OnDismissListener? = null,
): Pair<T, BottomSheetDialog> {
val layout = bindingInflater.invoke(LayoutInflater.from(this@makeBottomSheetDialog))
val dialog = BottomSheetDialog(this).apply {
setContentView(layout.root)
setOnDismissListener(onDismissListener)
setCancelable(isCancelable)
}.apply {
behavior.apply {
setHideable(isHideable)
isFitToContents = isFitContent
if(peekHeight != null) setPeekHeight(peekHeight)
}
}
return Pair(layout, dialog)
}
I've already researched this problem, and everyone suggests creating its own class, but in my case I want it to have a flexible view and easy to call with inline. When I saw the base code of BottomSheetDialog I thougth its because the container (FrameLayout) height not adjusted when BottomSheet is Expanded.
Question
how can I fix this problem? it makes me can't attach the button at the bottom of the view either. Thank you!
There is a way with which you can do this:
In XML layout of the dialog:
In the view, where you are calling the dialog, make a
BottomSheetBehavior
variable of theRelativeLayout
type.private lateinit var bottomSheetBehaviour: BottomSheetBehavior<RelativeLayout>
Then, call your dialog like this,
This will make your dialog layout go full screen when the user slides up the layout.