Issue
Every method I came across to hide status bar of my Android app is deprecated in Android 11.
Does anyone know about any current acceptable method?
Also I use Kotlin to develop my apps.
Solution
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()
);
Answered By - hata
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.