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

3

5

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>
Flitter answered 9/10, 2023 at 6:58 Comment(1)
I've also had this problem, which seems to be related to specific @Composable functions.Milky
W
5

I removed it by calling the splashscreen before the enableEdgeToEdge:

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    installSplashScreen().apply {
        setKeepOnScreenCondition {
            viewModel.isLoading.value
        }
    }

    enableEdgeToEdge()

    setContent {
Wootan answered 31/5 at 21:11 Comment(0)
M
4

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

Milky answered 13/10, 2023 at 13:15 Comment(1)
I tried both ways and get the same result... the accepted andwer, to move the installSplashScreen call to before the enableEdgeToEdge call, fixed the issue for meTithable
P
3

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.

Pejoration answered 18/12, 2023 at 14:47 Comment(1)
I can confirm that this is the working answer. Funny how much time I spent trying to figure out what's wrong.Taligrade

© 2022 - 2024 — McMap. All rights reserved.