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.
View decorView = getWindow(). getDecorView(); // Hide the status bar.
Go to Settings > Display >Notification shade > Turn the toggle off for 'Show icons for incoming notifications. '
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
WindowInsetsControllerinstead.
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()
);
API LEVEL < 16
If you want to hide the status bar in your application you can simply do this by making your app FULLSCREEN. Inside your onCreate method just add FLAG_FULLSCREEN
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_loading);
This is if Build.VERSION.SDK_INT < 16.
API LEVEL >= 16 AND < 30
This is for Build.VERSION.SDK_INT greater than 16;
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
Just add this inside your onCreate where you want to hide the status bar. More you can read here: https://developer.android.com/training/system-ui/status#41
EDIT: API LEVEL >= 30
It seems that SYSTEM_UI_FLAG_FULLSCREEN is also depricated from Android 11 even if it didn't say anything in the documentation. But based on this tutorial you can do this in Android 11 you need to use WindowInsetsController and its hide() method. Like the other answer suggested you can use:
getWindow().getDecorView().getWindowInsetsController().hide(
android.view.WindowInsets.Type.statusBars()
);
So, this is for Android 11 and later, other methods are for earlier versions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With