Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide navigationbar and statusbar in jetpack compose?

I already know about the Accompanist library to change the color of navigation and status bar.

The goal is to hide them completely.

like image 347
Daniel Weidensdörfer Avatar asked Sep 14 '25 08:09

Daniel Weidensdörfer


2 Answers

SystemUiController has a getter/setter method for system bar visibilities:

val systemUiController: SystemUiController = rememberSystemUiController()

systemUiController.isStatusBarVisible = false // Status bar
systemUiController.isNavigationBarVisible = false // Navigation bar
systemUiController.isSystemBarsVisible = false // Status & Navigation bars
like image 185
YASAN Avatar answered Sep 15 '25 22:09

YASAN


Since accompanist-systemuicontroller got deprecated, here is another solution.

With a disposable:

@Composable
fun HideSystemBars() {
    val context = LocalContext.current

    DisposableEffect(Unit) {
        val window = context.findActivity()?.window ?: return@DisposableEffect onDispose {}
        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
        }

        onDispose {
            insetsController.apply {
                show(WindowInsetsCompat.Type.statusBars())
                show(WindowInsetsCompat.Type.navigationBars())
                systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_DEFAULT
            }
        }
    }
}

fun Context.findActivity(): Activity? {
    var context = this
    while (context is ContextWrapper) {
        if (context is Activity) return context
        context = context.baseContext
    }
    return null
}

Or without one:

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
}
like image 34
Celsius Avatar answered Sep 15 '25 23:09

Celsius