I have created a Generic Bootm Sheet Creator. The bottom sheet takes up less than half the screen. However, once the bottom sheet is opened, I am unable to interact with the screen behind it. The other half where the bottom sheet isnt present doesnt let me intearct with that part of the screen.
class GenericBottomSheet(private val bottomSheettheme : Int): BottomSheetDialogFragment() {
var customView: View? = null
lateinit var bottomSheet: View
lateinit var bottomSheetBehavior: BottomSheetBehavior<View>
override fun getTheme(): Int = this.bottomSheettheme
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = BottomSheetDialog(requireContext(), theme)
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_dynamic_bottom_sheet, container, false)
bottomSheet = view.findViewById(R.id.bottom_sheet)
bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet)
bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
customView?.let {
val containerView = view.findViewById<FrameLayout>(R.id.dynamicContentContainer)
if (it.parent != null){
(it.parent as ViewGroup).removeView(it)
}
containerView.addView(it)
}
return view
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
companion object {
fun newInstance(customView: View,bottomSheettheme : Int = R.style.BottomSheetDialogTheme): GenericBottomSheet {
val fragment = GenericBottomSheet(bottomSheettheme)
fragment.customView = customView
return fragment
}
}
}
fragment_dynamic_bottom_sheet.xml
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android=";
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app=";
android:background="@android:color/transparent"
android:fitsSystemWindows="false">
<LinearLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_bottom_sheet"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<FrameLayout
android:id="@+id/dynamicContentContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"/>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>