Skip to content

Instantly share code, notes, and snippets.

@omarzer0
Last active June 22, 2023 02:43
Show Gist options
  • Save omarzer0/c569e83dd7d72131ade74faee064a6a4 to your computer and use it in GitHub Desktop.
Save omarzer0/c569e83dd7d72131ade74faee064a6a4 to your computer and use it in GitHub Desktop.
fun Activity.changeStatusAndNavigationBarVisibility(
hideStatusBar: Boolean = true,
hideNavigationBar: Boolean = true,
) {
// if (Build.VERSION.SDK_INT >= 30) {
// rootView.windowInsetsController?.hide(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars())
// } else {
// rootView.systemUiVisibility = View.SYSTEM_UI_FLAG_LOW_PROFILE or
// View.SYSTEM_UI_FLAG_FULLSCREEN or
// View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
// View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
// View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
// View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
//
// }
val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView)
windowInsetsController.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
if (hideStatusBar) windowInsetsController.hide(WindowInsetsCompat.Type.statusBars())
else windowInsetsController.show(WindowInsetsCompat.Type.statusBars())
if (hideNavigationBar) windowInsetsController.hide(WindowInsetsCompat.Type.navigationBars())
else windowInsetsController.show(WindowInsetsCompat.Type.navigationBars())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment