Status/Navigation Bar not Displayed correctly on Startup - Edge To Edge

186 Views Asked by At

I've just replaced a deprecated accompanist SysteUiController with an Activity Component's Edge to Edge. And it works just fine. However I've noticed that during a startup status/navigation bars don't look the way they should. Even if it's only for a second, I was wondering if there's a way to avoid that somehow?

The first image shows how it looks like on startup.

enter image description here enter image description here

MainActivity:

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        enableEdgeToEdge(
            statusBarStyle = SystemBarStyle.light(
                Color.TRANSPARENT, Color.TRANSPARENT
            ),
            navigationBarStyle = SystemBarStyle.light(
                Color.TRANSPARENT, Color.TRANSPARENT
            )
        )
        super.onCreate(savedInstanceState)
        setContent {
            CompTestTheme {
                MainScreen()
            }
        }
    }
}

Root composable:

...
if (!view.isInEditMode) {
    SideEffect {
        val window = (view.context as Activity).window
        window.statusBarColor = Color.Transparent.toArgb()
        WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !darkTheme
    }
}

MaterialTheme(
    colorScheme = colorScheme,
    typography = Typography,
    content = content
)
0

There are 0 best solutions below