- i want to fill the image to max size of page and fill the edges below the appbar.
- i can fill the image to full background without using scaffold but in this case i need to use scaffold.
- the screenshot is attached with the question for better understanding
- u can check it by tapping on the link enter image description here
@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
)
}
}
}
the image cant fill the the edges of app bar
CodePudding user response:
I tried this code and it's working. The important thing here is to make sure that the content you put inside Scaffold
should have some transparent area otherwise the background image won't be visible.
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
}
}