Hide notification bar on splash screen API 31

576 Views Asked by At

Is it possible to hide the notification bar on splash screen with the new Android 12 Splash screen API? So that the notification bar would be hidden from the very moment when the user launches an app.

I tried adding this to my Theme.SplashScreen

<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>

but it doesn't seem to do anything.

2

There are 2 best solutions below

1
On
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

Put above code in onCreateMethod of the activity of Splash Screen.

0
On

I don't think you can. I've also tried all different methods including :

1. SplashScreen Theme

<style name="Theme.SplashScreen.MySplash" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">#FFFFFF</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_launch</item>
    <item name="windowSplashScreenAnimationDuration">5000</item>
    <item name="postSplashScreenTheme">@style/Theme.ComposeDemos</item>
    <item name="android:windowTranslucentNavigation">false</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowDrawsSystemBarBackgrounds">false</item>
</style>

2. Code for hiding status bar suggested by Android

// onCreate
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
actionBar?.hide()

// and
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
    window.insetsController?.hide(WindowInsets.Type.statusBars())
} else {
    window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN)
}

nothing works. The code parts only affects the first Activity and not Splash Screen.

I think the closest you can do is to create an Splash screen activity instead of using SplashScreen API.