2

I'm learning Jetpack Compose with Kotlin, and trying to make an app with the option to enable fullscreen mode in Android, only showing the status bar after swiping it down.

I've searched for examples online, but none of them worked for me yet.

Some can hide the status bar, but still left a black bar; some can display full screen UI, but the status bar contents are still there.

The default project gives me

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            ...
        }
    }
}

what I've got is immersive

Then I added codes after enableEdgeToEdge()

val insetsController = WindowCompat.getInsetsController(window, window.decorView)
insetsController.apply {
    hide(WindowInsetsCompat.Type.statusBars())
    hide(WindowInsetsCompat.Type.navigationBars())
    systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}

What I've got is the black status bar area

3
  • 1
    Have you read through this example from Google? Or this guide from January? Immersive mode can be tricky to implement perfectly, but if you need help, you'll need to show us your code first. Commented Mar 21, 2024 at 8:53
  • The keyword to look for ist "edge to edge". Commented Mar 21, 2024 at 10:39
  • I'm not sure if the code is enough to ask for help, now I have no idea to deal with it.@Holo Commented Mar 22, 2024 at 1:16

1 Answer 1

0

Sample Activity code

override fun onCreate(savedInstanceState: Bundle?) {
    enableEdgeToEdge()
    super.onCreate(savedInstanceState)
    setContent {
        AllConceptsPracticeTheme {
            // A surface container using the 'background' color from the theme
            TransparentBarsApp()
        }
    }
}

@Composable
fun TransparentBarsApp() {
    val view = LocalView.current
    val useDarkIcons = !isSystemInDarkTheme()
    SideEffect {
        val window = (view.context as Activity).window
        window.statusBarColor = Color.Transparent.toArgb()
        window.navigationBarColor = Color.Transparent.toArgb()
        val insetsController = WindowCompat.getInsetsController(window, view)
        insetsController.isAppearanceLightStatusBars = useDarkIcons
        insetsController.isAppearanceLightNavigationBars = useDarkIcons
    }
    // Your screen content
    KeepNotesApp()
}
Sign up to request clarification or add additional context in comments.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

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.