我不知道我的背景从何而来
I don't know where my background comes from
我已经在 Compose 中打下基础 sheet。
目标是让底部sheet(图片所在的位置)的顶部透明,以便看到背景图片。
底部的其余部分 sheet 与文本将有一个背景
这是我想出的:
@ExperimentalMaterialApi
@Composable
fun EntryFragment() {
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = rememberBottomSheetState(BottomSheetValue.Collapsed)
)
BottomSheetScaffold(
scaffoldState = bottomSheetScaffoldState,
sheetContent = {
Box(
Modifier
.fillMaxWidth()
.fillMaxHeight().background(Color.Transparent)
) {
Column(Modifier.background(Color.Transparent)) {
Image(
painter = painterResource(R.drawable.main_screen_picture),
contentDescription = "Picture",
/*contentScale = ContentScale.Crop, */
modifier = Modifier.width(150.dp).height(150.dp)
)
Box(
Modifier
.fillMaxWidth()
.fillMaxHeight()
.background(Color.Blue)
){
Text(text = "Hello from sheet")
}
}
}
}, sheetPeekHeight = 600.dp
, modifier = Modifier.background(Color.Green)
) {
//Under the bottom sheet
Image(
painter = painterResource(R.drawable.main_screen_background),
contentDescription = "Background",
contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxWidth()
)
}
}
我的照片旁边有 white/black(取决于 day/night)背景。
貌似是专栏里的,不过都是透明背景。
我在底部设置了绿色背景sheet,但没有显示出来,所以问题肯定出在上面。
这个问题从何而来?
尝试将您的背景作为第一个修饰符,因为顺序很重要。例如:
Box(
Modifier
.background(Color.Transparent)
.fillMaxWidth()
.fillMaxHeight()
)
由BottomSheetScaffold
的sheetBackgroundColor
参数控制。作为下一步,您可能还需要禁用阴影:
sheetBackgroundColor = Color.Transparent,
sheetElevation = 0.dp,
我已经在 Compose 中打下基础 sheet。
目标是让底部sheet(图片所在的位置)的顶部透明,以便看到背景图片。 底部的其余部分 sheet 与文本将有一个背景
这是我想出的:
@ExperimentalMaterialApi
@Composable
fun EntryFragment() {
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = rememberBottomSheetState(BottomSheetValue.Collapsed)
)
BottomSheetScaffold(
scaffoldState = bottomSheetScaffoldState,
sheetContent = {
Box(
Modifier
.fillMaxWidth()
.fillMaxHeight().background(Color.Transparent)
) {
Column(Modifier.background(Color.Transparent)) {
Image(
painter = painterResource(R.drawable.main_screen_picture),
contentDescription = "Picture",
/*contentScale = ContentScale.Crop, */
modifier = Modifier.width(150.dp).height(150.dp)
)
Box(
Modifier
.fillMaxWidth()
.fillMaxHeight()
.background(Color.Blue)
){
Text(text = "Hello from sheet")
}
}
}
}, sheetPeekHeight = 600.dp
, modifier = Modifier.background(Color.Green)
) {
//Under the bottom sheet
Image(
painter = painterResource(R.drawable.main_screen_background),
contentDescription = "Background",
contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxWidth()
)
}
}
我的照片旁边有 white/black(取决于 day/night)背景。
貌似是专栏里的,不过都是透明背景。 我在底部设置了绿色背景sheet,但没有显示出来,所以问题肯定出在上面。
这个问题从何而来?
尝试将您的背景作为第一个修饰符,因为顺序很重要。例如:
Box(
Modifier
.background(Color.Transparent)
.fillMaxWidth()
.fillMaxHeight()
)
由BottomSheetScaffold
的sheetBackgroundColor
参数控制。作为下一步,您可能还需要禁用阴影:
sheetBackgroundColor = Color.Transparent,
sheetElevation = 0.dp,