After implementing the Splash Screen API as indicated by Android documentation (also this and this), the launch activity (which goes right after the splash screen) does not have dynamic color theming like the rest of the app. The splash screen <style>
has the <item name="postSplashScreenTheme">@style/Theme.App</item>
attribute which is supposed to apply the base application theme to the launch activity after the splash screen is cleared, but it doesn't. Everything else has been implemented like documentation dictates to a tee (activity class, manifest file, activity class, and themes.xml files).
I have tried all possible combinations, and the only one that "works" is when not setting the initial activity theme (or the whole activity) as the splash screen in the manifest (ie. android:theme="@style/Theme.App.Starting"
). But then why would the documentation insist you do? What can I do to make it work as intended?
Edit: as requested, relevant code
Splash Theme:
<!-- Splash Screen Theme. -->
<style name="Theme.App.Starting" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">?android:attr/colorBackground</item>
<item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher_round</item>
<item name="windowSplashScreenAnimationDuration">200</item>
<item name="postSplashScreenTheme">@style/Theme.App</item>
<!-- Status bar and Nav bar configs -->
<item name="android:statusBarColor" tools:targetApi="l">?android:attr/colorBackground</item>
<item name="android:navigationBarColor">?android:attr/colorBackground</item>
<item name="android:windowLightStatusBar">true</item>
</style>
manifest (only relevant attributes):
<application
android:name=".application.App"
android:theme="@style/Theme.App"
tools:targetApi="31">
<activity
android:name=".ui.MainActivity"
android:theme="@style/Theme.App.Starting">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
MainActivity:
override fun onCreate(savedInstanceState: Bundle?) {
setupSplashScreen()
super.onCreate(savedInstanceState)
/*...*/
}
Application class:
class App : Application() {
override fun onCreate() {
super.onCreate()
// Apply dynamic color
DynamicColors.applyToActivitiesIfAvailable(this)
}
}
Edit Jul 5, 2023: (possibly) final update
After a tremendous amount of testing and research, I have come to the conclusion that this is a bug and it cannot/will not be fixed anytime soon. I have also pin-pointed the reason for it.
The bug has been reported over a year and a half ago, and the reason it happens is that after the library calls postSplashScreenTheme
, it sets the base theme of the app again which gets rid of the Material You (dynamic) colors. Another project encountered the same issue, which prevented them from implementing Material You for them. Someone suggested setting DynamicColors.applyToActivitiesIfAvailable(this)
in each activity after the installSplashScreen()
, but the status bar retained the base theme color instead of the dynamic color so it was useless. In my experiments, I found another workaround: not setting any splash theme in manifest (android:theme="@style/Theme.App.Starting"
) seems to work on api level 31+, but prevents the splash screen icon from showing at all in previous levels so it is also useless.
As of this update, Splash Screen API and Material You (dynamic color) conflict with each other and are therefore mutually exclusive. I will not be using dynamic colors since I need the functionality to load data at app start from splash screen api.