2

I have application with white color status bar and navigation bar. I have define a Splash theme like this.

<style name="Theme.MySplash" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">#00f</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_baseline_play_arrow_24</item>
    <item name="windowSplashScreenAnimationDuration">200</item>

    <item name="postSplashScreenTheme">@style/Theme.AppTheme</item>
</style>

<style name="Theme.AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <item name="android:statusBarColor">#fff</item>
    <item name="android:navigationBarColor">#fff</item>
</style>

MainActivity

class MainActivity : AppCompatActivity() {

    var keepSplashScreen = true

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val splashScreen = installSplashScreen()

        splashScreen.setOnExitAnimationListener { splashScreenProvider ->
            val fadeAnim = ObjectAnimator.ofFloat(
                splashScreenProvider.view, View.ALPHA, 1f, 0f
            )
            fadeAnim.duration = 4000L
            fadeAnim.interpolator = AccelerateInterpolator()
            fadeAnim.doOnEnd { splashScreenProvider.remove() }
            fadeAnim.start()
        }
        splashScreen.setKeepVisibleCondition { keepSplashScreen }
        setContentView(R.layout.activity_main)

        Handler(Looper.getMainLooper()).postDelayed({
            keepSplashScreen = false
        }, 3000)
    }
}

SplashTheme working well on device Android 12 (Pixel 4XL) but on Android 8 (Xiomi A2), the SplashTheme won't display full screen when it exist.

enter image description here

From this video, when SplashScreen start exist (fade animation), the white status bar and navigation bar is display (on Android 12, SplashScreen always fullscreen while exist). How can I make the SplashScreen always fullscreen on Android < 12?

Linh
  • 57,942
  • 23
  • 262
  • 279
  • I have a similar problem. I want to animate from the Splash to a Screen drawing the status bar. When the animation starts, the target screen shows a black space on the top and on the bottom of the screen. And, at the end of the animation, the screen is resized to cover all the screen. So the UX is very poor. – Rubén Jun 02 '23 at 11:16

2 Answers2

0

Try this:

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

Write it inside your onCreate Method. For more, Read this.

  • Thanks but still same problem. I already try flag FLAG_FULLSCREEN or setDecorFitsSystemWindows – Linh Dec 14 '21 at 08:51
  • Make a new SplashActivity, and try in that. It seems there is a problem in your code. Because this should work. –  Dec 14 '21 at 08:53
  • Also, check if this is not a device-specific issue. –  Dec 14 '21 at 08:53
  • It happened on my main app and I created a demo (all code is inside the question). I just test on Samsung A51 (Android 11), still same problem like Android 8 – Linh Dec 14 '21 at 09:02
0

I think the problem maybe you do not use the compact library. If you’re not using the support library, your splash screen will exactly have the same old look in lower versions as you had before.

implementation 'androidx.core:core-splashscreen:1.0.0-alpha01'

the SplashScreen actually use a frame layout that contains a image view

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="false">

  <ImageView
      android:id="@+id/splashscreen_icon_view"
      android:layout_width="?attr/splashScreenIconSize"
      android:layout_height="?attr/splashScreenIconSize"
      android:layout_gravity="center"/>

</FrameLayout>
Lenoarod
  • 3,441
  • 14
  • 25
  • I'm using `androidx.core:core-splashscreen:1.0.0-alpha02` version. I will try to downgrade it to alpha01 – Linh Dec 14 '21 at 09:28
  • @Linh if you use the support library, it may be the theme problem. you don need to downgrade – Lenoarod Dec 14 '21 at 09:38
  • 1
    look like the library problem, after downgrade to alpha01, this problem won't happened but another problem happened :(. (the app icon on SplashScreen look smaller than alpha01 version – Linh Dec 14 '21 at 09:42
  • @Linh, in the end, that‘s good, but werid. the icon small because you don't put It in the correct folder, try to change it. – Lenoarod Dec 14 '21 at 09:44
  • actually, I use vector drawable for icon so I don't think it's from drawable folder. same device dimension but on Android 12 version, it look bigger – Linh Dec 14 '21 at 09:47
  • anyway, I think small icon still better than white background on statusbar and navigation bar. I will downgrade to alpha01 – Linh Dec 14 '21 at 09:53