Last active
September 24, 2020 10:16
-
-
Save milhauscz/096f156e2f9cfa840e2615beef1340a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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