Android.View.View.Systemuivisibility Deprecated. What Is the Replacement

How to change systemUIVisibility on SdkVersion 30

Yes now since it is deprecated, you can use:

window.setDecorFitsSystemWindows(false)

Then make sure you make the status bar transparent as well by adding below style to your app theme

<item name="android:navigationBarColor">@android:color/transparent</item>

Hope this helps :)

decorView.systemUiVisibility deprecated. How to replace it correctly?

Try this methode to change status bar with new api or old :

  private fun changeSystemStatusBarColor() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val window = window
val decorView = window.decorView
val wic = WindowInsetsControllerCompat(window, decorView)
wic.isAppearanceLightStatusBars = false // true or false as desired.
// And then you can set any background color to the status bar.
window.statusBarColor = ContextCompat.getColor(
this,
R.color.black
)
} else {
window.decorView.systemUiVisibility =
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; // set status text dark
window.statusBarColor = ContextCompat.getColor(
this,
R.color.black
)
}
setStatusBarLightText(window, true)
return
}

private fun setStatusBarLightText(window: Window, isLight: Boolean) {
setStatusBarLightTextOldApi(window, isLight)
setStatusBarLightTextNewApi(window, isLight)
}

private fun setStatusBarLightTextOldApi(window: Window, isLight: Boolean) {
val decorView = window.decorView
decorView.systemUiVisibility =
if (isLight) {
decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv()
} else {
decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
}
}

private fun setStatusBarLightTextNewApi(window: Window, isLightText: Boolean) {
ViewCompat.getWindowInsetsController(window.decorView)?.apply {
// Light text == dark status bar
isAppearanceLightStatusBars = !isLightText
}
}

Immersive fullscreen on Android 11

For compatibility, use WindowCompat and WindowInsetsControllerCompat. You'll need to upgrade your gradle dependency for androidx.core to at least 1.6.0-alpha03 so that there will be support for setSystemBarsBehavior on SDK < 30. mainContainer is the top-level ConstraintLayout in my activity.

private fun hideSystemUI() {
WindowCompat.setDecorFitsSystemWindows(window, false)
WindowInsetsControllerCompat(window, mainContainer).let { controller ->
controller.hide(WindowInsetsCompat.Type.systemBars())
controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
}

private fun showSystemUI() {
WindowCompat.setDecorFitsSystemWindows(window, true)
WindowInsetsControllerCompat(window, mainContainer).show(WindowInsetsCompat.Type.systemBars())
}

You can find out more information about WindowInsets by watching this YouTube video

EDIT:

I didn't consider display cutouts or in-display cameras in this answer previously. In the app theme style, i added the following to display my content above the cutout (to the top of the screen when in portrait mode):

<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>

You can read more at this link: Display Cutout

Non-deprecated way to hide status bar on android?

You could use this:

FrameLayout frameLayout = findViewById<FrameLayout>(R.id.mainView)
frameLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)

for the new android version, where R.id.mainView is your main layout.
Please check this for more details: https://proandroiddev.com/exploring-windowinsets-on-android-11-a80cf8fe19be

How do I hide the status bar in my Android 11 app?

When your device is API-30 (Android 11; minSdkVersion 30) or later , setSystemUiVisibility is deprecated and you can use the newly introduced WindowInsetsController instead. (And note that you cannot use WindowInsetsController on API-29 or earlier).

So the official reference says:

This method was deprecated in API level 30.
SystemUiVisibility flags are deprecated. Use WindowInsetsController instead.

You should use WindowInsetsController class.

in Kotlin:

window.decorView.windowInsetsController!!.hide(
android.view.WindowInsets.Type.statusBars()
)

in Java:

getWindow().getDecorView().getWindowInsetsController().hide(
android.view.WindowInsets.Type.statusBars()
);

If you also want to hide NavigationBar:

in Kotlin:

window.decorView.windowInsetsController!!.hide(
android.view.WindowInsets.Type.statusBars()
or android.view.WindowInsets.Type.navigationBars()
)

in Java:

getWindow().getDecorView().getWindowInsetsController().hide(
android.view.WindowInsets.Type.statusBars()
| android.view.WindowInsets.Type.navigationBars()
);


Related Topics



Leave a reply



Submit