我正在使用BottomSheetScaffold显示一个BottomSheet。
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = rememberBottomSheetState(
initialValue = BottomSheetValue.Collapsed
)
)
BottomSheetScaffold(
sheetContent = {
MySheet()
},
scaffoldState = bottomSheetScaffoldState) {
MyMainContent()
}
)现在,我想在工作表上方显示元素,当展开或关闭工作表时,这些元素将会移动。例如:

元素不是FloatingActionButtons。
有没有我可以用的修饰语?这可以通过Box布局来实现吗?有没有一些CoordinatorLayout模式?我需要写我自己的布局吗?
总而言之:我如何使用Jetpack Compose实现这一点?
发布于 2021-07-09 20:54:28
我不知道compose (rc01版本)中有没有内置的东西。但是您可以通过将透明颜色设置为sheetBackgroundColor参数来实现此行为...如下所示:
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = rememberBottomSheetState(
initialValue = BottomSheetValue.Collapsed
)
)
BottomSheetScaffold(
// the whole sheet will be transparent.
sheetBackgroundColor = Color.Transparent,
sheetContent = {
Column {
Text(
text = "Element",
Modifier
.align(Alignment.CenterHorizontally)
.wrapContentWidth()
.background(Color.Red)
.padding(24.dp)
)
// Your bottom sheet content
Box(
Modifier
.fillMaxWidth()
.background(Color.White)) {
// content
}
}
},
scaffoldState = bottomSheetScaffoldState
) {
// The main content
Box(
Modifier
.fillMaxSize()
.background(Color.Black)) {
}
}结果如下:

https://stackoverflow.com/questions/68315295
复制相似问题