最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - BottomSheetDialogFragment not letting interaction with the back screen - Stack Overflow

programmeradmin3浏览0评论

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>
发布评论

评论列表(0)

  1. 暂无评论