AndroidX's Edge to Edge shows an Action Bar - How to hide it?

590 Views Asked by At

I've implemented Edge to Edge in my Android app, I've set the Status/Navigation bars to be transparent, and it works well. However suddenly an ActionBar appeared on top of my screen, even though I've set the app theme to be "android:Theme.Material.Light.NoActionBar". How can I fix that?

MainActivity:

    override fun onCreate(savedInstanceState: Bundle?) {
        enableEdgeToEdge(
            statusBarStyle = SystemBarStyle.light(
                Color.TRANSPARENT, Color.TRANSPARENT
            ),
            navigationBarStyle = SystemBarStyle.light(
                Color.TRANSPARENT, Color.TRANSPARENT
            )
        )
        super.onCreate(savedInstanceState)
    }

Root composable:

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

themes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.TestApp" parent="android:Theme.Material.Light.NoActionBar" />
</resources>
2

There are 2 best solutions below

0
Alsser On

Have you used the SplashScreen API in your code? If you have used this API, in the AndroidManifest.xml file, when the theme of the starting activity is set at position 2, the ActionBar will be displayed. However, according to the official guide, both approaches are expected to have the same effect. It's puzzling that placing it at 2 displays the ActionBar while 1 does not.enter image description here

0
Maher Safadi On

I've been trying to solve this for hours and no solutions worked, since I use the new Splash API, I fixed it by replacing enableEdgeToEdge() before installSplashScreen() and it worked.