the way I tackled this issue was the following:
- Implement BottomSheetDialogFragment
- override onCreateDialog
- get reference for bottomSheetDialog and set a onShowListener
- Remove button from my layout and add it to R.id.container (of course you can create your own button programatically, I've done it this to be easier to format the button view). This way your button will be over the R.id.design.bottom.sheet since R.id.container is it's parent!
Example code following:
val bottomSheetDialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
bottomSheetDialog.setOnShowListener {
val dialog = it as BottomSheetDialog
dialog.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet) as FrameLayout
val containerLayout: FrameLayout =
dialog.findViewById<FrameLayout>(com.google.android.material.R.id.container) as FrameLayout
val button = binding.submitButton
val parent = button.parent as ViewGroup
parent.removeView(button)
containerLayout.addView(button, containerLayout.childCount)
}
return bottomSheetDialog
This way your bottom sheet will respond to touches normally and the button will stay on it's position on the parent.
If you have any doubt feel free to ask.
EDIT
Don't forget to define layout params/positioning the button for it to be on the bottom of R.id.container