How do I make the Android navigation bar auto-hide after a period of time?

536 Views Asked by At

I use the following call to hide the system navigation bar when my activity starts.

WindowInsetsControllerCompat(window, window.decorView).hide(WindowInsetsCompat.Type.systemBars())

When the user swipes up from the bottom to make the navigation bar appear, it stays on screen forever after that. The behavior I want is for the navigation bar to auto-hide after several seconds if the user doesn't tap on a navigation button.

Is there a way to make the system navigation bar do that on its own, or do I need to create my own timer to do it?

Note: I'm testing on a Samsung S22.

1

There are 1 best solutions below

1
Byte Code On

Call this function in your Activity.

private fun hideSystemUI() {
    WindowCompat.getInsetsController(window, window.decorView).systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
    window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
}