Why the colors-night is not triggered while Splashscreen is running?

Viewed 24

I use the Core Splashscreen by Google in my app and that works perfectly. However, when it comes to a dark mode, the splash screen does not use trigger colors from colors.xml in values-night. Here is my implementation:

<application
        android:name=".App"
        android:allowBackup="false"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MaApp"
        tools:targetApi="31">
        <activity
            android:name=".activities.MainActivity"
            android:exported="true"
            android:theme="@style/Theme.Starting">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

Base theme:

<style name="Base.Theme.MyApp" parent="Theme.Material3.DayNight.NoActionBar">
        <item name="textAllCaps">false</item>
        <item name="colorSecondary">@color/secondary</item>
    </style>

Light theme:

<resources>

    <style name="Theme.MyApp" parent="Base.Theme.MyApp">
        <item name="colorPrimary">@color/primary</item>
        <item name="android:windowLightStatusBar">true</item>
        <item name="android:windowLightNavigationBar">true</item>
    </style>

    <style name="Theme.Starting" parent="Theme.SplashScreen.IconBackground">
        <item name="windowSplashScreenBackground">@color/primary</item>
        <item name="postSplashScreenTheme">@style/Theme.MyApp</item>
        <item name="windowSplashScreenIconBackgroundColor">@android:color/white</item>
        <item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>
    </style>
</resources>

Dark theme:

<resources>
    
        <style name="Theme.MyApp" parent="Base.Theme.MyApp">
            <item name="colorPrimary">@color/primary</item>
            <item name="android:windowLightStatusBar">false</item>
            <item name="android:windowLightNavigationBar">false</item>
        </style>

    <style name="Theme.Starting" parent="Theme.SplashScreen.IconBackground">
        <item name="windowSplashScreenBackground">@color/primary</item>
        <item name="postSplashScreenTheme">@style/Theme.MyApp</item>
        <item name="windowSplashScreenIconBackgroundColor">@android:color/white</item>
        <item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>
    </style>
</resources>

Light colors:

<resources>
    <color name="primary">#0091EA</color>
    <color name="secondary">#246EE9</color>
</resources>

Dark colors:

<resources>
    <color name="primary">#062C3A</color>
    <color name="secondary">#246EE9</color>
</resources>

App.kt:

class App : Application() {
    override fun onCreate() {
        
        val mode = when (Prefs(this).int(THEME)) {
            0 -> AppCompatDelegate.MODE_NIGHT_NO
            1 -> AppCompatDelegate.MODE_NIGHT_YES
            else -> if (isMax28)
                AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY
            else
                AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
        }
        AppCompatDelegate.setDefaultNightMode(mode)
       

        super.onCreate() // No matter whether this is before or after the theme called.
    }
}

Whenever the app starts in dark mode, the splash screen uses light colors. But after splash screen there is no issues with dark mode, which means I all colors are used in dark mode correctly.

Why does the <item name="windowSplashScreenBackground">@color/primary</item> is in light mode only?

Thanks.

0 Answers
Related