10

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>
1
  • I've also had this problem, which seems to be related to specific @Composable functions. Commented Oct 13, 2023 at 13:25

3 Answers 3

25

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 {
Sign up to request clarification or add additional context in comments.

Comments

5

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

1 Comment

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 me
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.

1 Comment

I can confirm that this is the working answer. Funny how much time I spent trying to figure out what's wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.