Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hideSystemUI method is deprecated ? #55

Open
AgungLaksana opened this issue Nov 10, 2020 · 1 comment
Open

hideSystemUI method is deprecated ? #55

AgungLaksana opened this issue Nov 10, 2020 · 1 comment

Comments

@AgungLaksana
Copy link

I am trying to follow this step in here https://developer.android.com/codelabs/exoplayer-intro#2

but when I implement hideSystemUi method in Kotlin. then code seems deprecated
like this https://i.stack.imgur.com/uqAUP.png

@SuppressLint("InlinedApi")
    private fun hideSystemUi() {
        playerView.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)
    }

how to solve this ?

@wax911
Copy link

wax911 commented Dec 8, 2020

You can add a API version check and if you're using API 30+ try out window insets, refer to this video to learn more about
window insets and medium post here

I have to admit, insets still feel like a mess and still have a lot of question regarding how to migrate and replace all the window flags with insets. Personally I'd I've managed to achieve the following use-case by doing the following:

/**
 * Hides both status bar and navigation bar
 */
fun FragmentActivity.hideStatusBarAndNavigationBar() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        WindowCompat.setDecorFitsSystemWindows(window, true)
        val controller = ViewCompat.getWindowInsetsController(window.decorView)

        // swipe in system bars, this is now sticky immersive
        controller?.systemBarsBehavior =
            WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE

        // hide status and navigation bar
        controller?.hide(WindowInsets.Type.systemBars())
    } else {
        // Until I figure out how to hide status bar and nav pre android R using insets
        @Suppress("DEPRECATION")
        window.decorView.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
    }
}

As my comments suggestion the insets work for everything except for hiding status bar in pre-android R so instead since I only use insets if the current version is API 30+

Hope this will also help you! 😄

Be sure to watch the video for more context 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants