Search code examples
android-jetpack-composestatusbar

Android Jetpack Compose statusbar height?


How can I get the statusbar height? Accompanist Insets is now deprecated, and WindowInsets.systemBars.asPaddingValues() gives me 0 every time... And Modifier.statusBarsPadding() does nothing in my layout. Is there any way to get this height?!?


Solution

  • When i call WindowCompat.setDecorFitsSystemWindows(window, false) before setContent on Activity i get correct values otherwise it returns 0

    @Composable
    private fun MyComposable() {
        Column {
            val paddingValues = WindowInsets.systemBars.asPaddingValues()
            Spacer(modifier=Modifier.height(paddingValues.calculateTopPadding()))
            Text(text = "Padding values: $paddingValues")
        }
    }
    

    Result

    enter image description here

    Without WindowCompat.setDecorFitsSystemWindows(window, false)

    enter image description here