You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何实现Bottom Sheet允许外部触摸?现有方案无效求助

问题:BottomSheetDialog点击外部仍会关闭,无法触摸后方区域

我尝试实现允许触摸Bottom Sheet后方的区域,但设置各类标志与修饰符后,点击外部仍会关闭Bottom Sheet。

Bottom Sheet布局代码

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_gravity="bottom"
    android:background="@color/blue"
    android:paddingStart="16dp"
    android:paddingEnd="16dp"
    android:paddingBottom="15dp"
    app:behavior_hideable="true"
    app:layout_behavior="@string/bottom_sheet_behavior">

    <TextView
        android:id="@+id/tvSaveFilter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:text="ok"
        android:textColor="@color/white"
        android:textSize="15sp"
        android:textStyle="normal"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/rSaveFilterButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:text="save?"
        android:textColor="@color/white"
        android:textSize="15sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

初始化Bottom Sheet的代码

val bottomSheetDialog =
    BottomSheetDialog(requireContext())
val layout = saveBottomSheetBinding.inflate(LayoutInflater.from(requireContext()))
bottomSheetDialog.setContentView(layout.root)
bottomSheetDialog.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
bottomSheetDialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)

bottomSheetDialog.show()

我曾尝试过一个解决方案但无效,希望有遇到过该问题的开发者提供帮助。

内容的提问来源于stack exchange,提问作者Spectator

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 06:05:21