Sum*_*med 5 background appbar scaffold kotlin android-jetpack-compose
@Composable
fun ScaffoldBackground() {
Scaffold(
topBar = {
TopAppBar(
modifier = Modifier
.fillMaxHeight(0.2f)
.clip(
shape = RoundedCornerShape(bottomEnd = 30.dp, bottomStart = 30.dp)
),
// Provide Title
title = {
Text(
text = "Dashboard",
)
}
)
},
) {
Box(
modifier = Modifier
.fillMaxSize()
) {
Image(
modifier = Modifier
.fillMaxSize(),
painter = painterResource(R.drawable.ic_launcher_background),
contentDescription = "background_image",
contentScale = ContentScale.FillBounds
)
}
}
}
Run Code Online (Sandbox Code Playgroud)
Arp*_*kla 15
我尝试了这段代码并且它有效。这里重要的是确保您放入的内容Scaffold应该有一些透明区域,否则背景图像将不可见。
Box {
Image(
modifier = Modifier.fillMaxSize(),
painter = painterResource(R.drawable.ic_launcher_background),
contentDescription = "background_image",
contentScale = ContentScale.FillBounds
)
Scaffold(
backgroundColor = Color.Transparent, // Make the background transparent
topBar = {
TopAppBar(
modifier = Modifier
.fillMaxHeight(0.2f)
.clip(
shape = RoundedCornerShape(
bottomEnd = 30.dp,
bottomStart = 30.dp
)
),
title = {
Text(text = "Dashboard")
}
)
},
) {
// Scaffold content
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10514 次 |
| 最近记录: |