mattinger
03/12/2025, 6:43 PMTheme.Material3.Light.NoActionBar
, calling the ComponentActivity.enableEdgeToEdge
function does not actually set the status bar color?
DisposableEffect(selected) {
activity?.enableEdgeToEdge(
if (selected.isLight) {
SystemBarStyle.light(selected.color.toArgb(), selected.darkColor.toArgb())
} else {
SystemBarStyle.dark(selected.color.toArgb())
}
)
onDispose {
}
}
Instead i'm having to manually set the color in a surface:
Surface(color = selected.color) {
Surface(
modifier = Modifier
.systemBarsPadding()
.navigationBarsPadding()
.displayCutoutPadding()
.fillMaxHeight()
) {
When running under older API levels (say 31), the color changes properly without the outer surface, but the displayCutoutPadding
does not seem to work.Oleg
03/13/2025, 7:09 PMmattinger
03/13/2025, 7:38 PMOleg
03/13/2025, 7:57 PMOleg
03/13/2025, 8:00 PMOleg
03/13/2025, 8:01 PMOleg
03/13/2025, 8:03 PMhugo
03/15/2025, 9:23 PMmattinger
03/17/2025, 1:23 PMWindowCompat.getInsetsController(it.window, activity.findViewById(android.R.id.content))
.isAppearanceLightNavigationBars = isNavigationBarLight
I've debugged this to make sure it's set to false, but the icons are always set as if it's a light nav bar.:mattinger
03/17/2025, 1:27 PMSystemBarStyle.dark
is enough for the buttons to be the proper color (black for a light background, white for a dark background)mattinger
03/17/2025, 1:28 PMhugo
03/17/2025, 2:48 PMenableEdgeToEdge(
statusBarStyle = SystemBarStyle.auto(0, 0, { /* dark */ true }),
navigationBarStyle = SystemBarStyle.auto(0, 0, { /* dark */ true })
)
No need to muck with the WindowInsetsController api and it will look consistent from 29+. If you want to support lower API levels, I'd copy the scrim values that are in SystemBarStyle.auto() for the navigation bar as well.
SystemBarStyle.dark()
should also work, but it disables the platform scrim on 29+ too so in that case you'd need to add your own scrim. If you go that route, I'd set the scrim colors to transparent too in that case to that everything looks the same on all (reasonable) API levels.hugo
03/17/2025, 2:51 PMmattinger
03/17/2025, 3:14 PM@Composable
@Preview(showSystemUi = true, showBackground = true)
private fun StatusBarExample2() {
fun Context.getComponentActivity(): ComponentActivity? = when (this) {
is ComponentActivity -> this
is ContextWrapper -> baseContext.getComponentActivity()
else -> null
}
val backgroundColor = Color(0xFF006851)
MaterialTheme {
val activity = LocalContext.current.getComponentActivity()
SideEffect {
activity?.enableEdgeToEdge(
SystemBarStyle.dark(Color.Transparent.toArgb()),
SystemBarStyle.dark(Color.Transparent.toArgb()),
)
}
Surface(
color = backgroundColor,
modifier = Modifier
.fillMaxSize()
) {
Surface(
modifier = Modifier
.fillMaxSize()
.statusBarsPadding()
.displayCutoutPadding()
.navigationBarsPadding()
) {
}
}
}
}
You still get a navigation bar with dark icons:mattinger
03/17/2025, 3:16 PMmattinger
03/17/2025, 3:18 PMhugo
03/17/2025, 3:21 PMmattinger
03/17/2025, 3:21 PMhugo
03/17/2025, 3:22 PMColor.Transparent.toArgb()
to 0 though.mattinger
03/17/2025, 3:22 PMmattinger
03/17/2025, 3:23 PMhugo
03/17/2025, 3:23 PMhugo
03/17/2025, 3:23 PMmattinger
03/17/2025, 3:24 PMhugo
03/17/2025, 3:25 PMmattinger
03/17/2025, 3:25 PMmattinger
03/17/2025, 3:29 PMhugo
03/17/2025, 3:29 PMmattinger
03/17/2025, 3:29 PMhugo
03/17/2025, 3:30 PMhugo
03/17/2025, 3:30 PMhugo
03/17/2025, 3:30 PMmattinger
03/17/2025, 3:31 PMmattinger
03/17/2025, 3:32 PM