I need to set background color for whole app. In xml, we use android:background
tag in fragment || activity.
What analog Compose has? Surface
argument for theme colorPalette doesn't help (background color doesn't changes). Where in code I need to set the background? Look for your solutions.
You can place your app inside a Box
with needed background:
setContent {
YourTheme {
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.Yellow)
) {
YourApp()
}
}
}
Put a window background color from your theme, which will set the background of your whole app, and also remove the white flicker while the app is loading (which looks quite odd if you have a color background in your app):
res/values/themes/themes.xml
<style name="Theme.YourThemeName"
parent="Theme.MaterialComponents.DayNight.DarkActionBar">
...
<item name="android:windowBackground">@color/purple_700</item>
</style>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.