Skip to content

Instantly share code, notes, and snippets.

@milhauscz
Last active September 24, 2020 10:16
Show Gist options
  • Save milhauscz/096f156e2f9cfa840e2615beef1340a6 to your computer and use it in GitHub Desktop.
Save milhauscz/096f156e2f9cfa840e2615beef1340a6 to your computer and use it in GitHub Desktop.
/**
* Shows the system bars and returns back from fullscreen.
* @see hideSystemUI
* @see addSystemUIVisibilityListener
*/
fun Activity.showSystemUI() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// show app content in fullscreen, i. e. behind the bars when they are shown (alternative to
// deprecated View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION and View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
window.setDecorFitsSystemWindows(false)
// finally, show the system bars
window.insetsController?.show(WindowInsets.Type.systemBars())
} else {
// Shows the system bars by removing all the flags
// except for the ones that make the content appear under the system bars.
@Suppress("DEPRECATION")
window.decorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment