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

如何移除Jetpack Compose中Bottom Sheet的底部内边距

解决Material 2 BottomSheetScaffold底部莫名出现内边距的问题

Material 2的BottomSheetScaffold默认会给sheetContent添加底部内边距,用来适配系统导航栏(虚拟按键、底部导航栏等),这是组件的默认行为,并非你代码里手动设置的。

你可以通过以下两种方式解决:

1. 直接移除所有底部内边距

在BottomSheetScaffold中添加sheetPadding = PaddingValues(0.dp)参数,覆盖默认的内边距设置:

BottomSheetScaffold(
      scaffoldState = scaffoldState,
      modifier = Modifier.fillMaxSize(),
      sheetBackgroundColor = UiColors.MeditationBottomSheetColor,
      sheetContentColor = Color.Black,
      sheetGesturesEnabled = currentBottomSheet == 1,
      sheetPeekHeight = 0.dp,
      sheetShape = ShapeDefaults.Medium,
      sheetPadding = PaddingValues(0.dp), // 新增这一行移除默认内边距
      sheetContent = {
          if (currentBottomSheet == 0) {
              GuidedMeditationStatisticsBottomSheetContent(
                  user = currentUser,
                  totalDurationInMs = currentPosition,
                  onDone = onDone
              )
          } else {
              InstrumentBottomSheet(
                  currentInstrument = currentInstrument,
                  instruments = instruments,
                  currentVolume = currentInstrumentVolume,
                  onVolumeChange = onVolumeChange,
                  onSelectedInstrument = onSelectedInstrument,
                  onCancel = onCancelInstrument
              )
          }
      },
      content = { 
//Content
})

2. 检查子组件是否自带内边距

如果添加sheetPadding后问题仍存在,去检查GuidedMeditationStatisticsBottomSheetContent和InstrumentBottomSheet的内部代码,看是否在根布局中设置了底部padding——很多时候额外内边距是子组件自身添加的。

内容的提问来源于stack exchange,提问作者Harsh Vardhan Tewari

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 18:35:09