Created
May 3, 2023 20:52
-
-
Save sonique6784/c6dd6b5fe1923206ff3b5292584ca93b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* immersiveExperience for Android | |
* set your app into immersive mode hidding navigation and status bar | |
* call this function in Activity#onCreate | |
*/ | |
private fun immersiveExperience() { | |
val windowInsetsController = | |
WindowCompat.getInsetsController(window, window.decorView) | |
// Configure the behavior of the hidden system bars. | |
windowInsetsController.systemBarsBehavior = | |
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE | |
// Add a listener to update the behavior of the toggle fullscreen button when | |
// the system bars are hidden or revealed. | |
window.decorView.setOnApplyWindowInsetsListener { view, windowInsets -> | |
// You can hide the caption bar even when the other system bars are visible. | |
// To account for this, explicitly check the visibility of navigationBars() | |
// and statusBars() rather than checking the visibility of systemBars(). | |
if (windowInsets.isVisible(WindowInsetsCompat.Type.navigationBars()) | |
|| windowInsets.isVisible(WindowInsetsCompat.Type.statusBars()) | |
) { | |
// Hide both the status bar and the navigation bar. | |
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()) | |
} | |
view.onApplyWindowInsets(windowInsets) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment