material-components-android-examples icon indicating copy to clipboard operation
material-components-android-examples copied to clipboard

systemUiVisibility is deprecated in Android R

Open akaSourav opened this issue 4 years ago • 1 comments

We use systemUiVisibility for full screen mode. But it is now deprecated. What will be the better alternative?

akaSourav avatar Aug 18 '20 07:08 akaSourav

I use this snippet for immersive screen.

private fun hideSystemUI() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        window.setDecorFitsSystemWindows(false)
        window.insetsController?.let {
            it.hide(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars())
            it.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
        }
    } else {
        @Suppress("DEPRECATION")
        window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                // Hide the nav bar and status bar
                or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                or View.SYSTEM_UI_FLAG_FULLSCREEN)
    }
}

asissuthar avatar Mar 11 '21 07:03 asissuthar