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

如何让Bottom Sheet关闭时不完全隐藏,保留顶部可拉起区域?

实现底部弹窗(Bottom Sheet)关闭时保留顶部可见的方案

完全可以实现这个需求,只需要调整Bottom Sheet Behavior的几个核心属性就能搞定:

  1. 修改布局属性
    • 将app:behavior_hideable="true"改为app:behavior_hideable="false",这个属性控制Bottom Sheet是否允许被完全隐藏,设为false后弹窗就不会彻底消失。
    • 添加app:behavior_peekHeight="60dp"(数值可根据你的实际需求调整),这个属性定义了Bottom Sheet收起状态下保留的可见高度,设置后收起时会固定显示该高度的区域,方便用户重新拉起。

修改后的布局代码如下:

<?xml version="1.0" encoding="utf-8"?>
<com.app.implementation.bottomsheet.BrowserBottomSheet 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="wrap_content"
    android:clickable="true"
    android:focusable="true"
    app:behavior_hideable="false"
    app:behavior_peekHeight="60dp"
    app:layout_behavior="@string/bottom_sheet_behavior" />
  1. 动态调整(可选)
    如果需要在代码中动态修改保留高度,可以通过获取BottomSheetBehavior实例操作:
// Kotlin示例
val bottomSheet = findViewById<BrowserBottomSheet>(R.id.your_bottom_sheet_id)
val behavior = BottomSheetBehavior.from(bottomSheet)
behavior.peekHeight = 180 // 单位为像素
behavior.isHideable = false

注意:peekHeight的数值要匹配你顶部可交互区域的大小,确保用户能轻松点击或拖拽拉起弹窗。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 02:18:13