question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[M3/DynamicColors] Dynamic Colors not applied when SplashScreen API is used

See original GitHub issue

Description:

When application or activity launcher theme inherits from Theme.SplashScreen and we set postSplashScreenTheme to a theme that inherits from Material3, it does not apply Dynamic Colors when we call DynamicColors.applyToActivitiesIfAvailable(this) on the Application class.

Expected behavior: Apply Dynamic colors.

Source code: https://github.com/serbelga/ToDometer/tree/feature/dynamicColors

Android API version: Android SDK 31 (Android 12)

Material Library version: 1.5.0

    <!-- Base application theme. -->
    <style name="Theme.ToDometer" parent="Theme.Material3.DayNight">
    ...
    </style>

    <style name="Theme.ToDometer.NoActionBar">
    ...
    </style>

    <style name="Theme.ToDometer.Starting" parent="Theme.SplashScreen">
        <item name="windowSplashScreenBackground">@color/navy</item>

        <item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>
        <item name="windowSplashScreenAnimationDuration">2000</item>

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

AndroidManifest.xml

    <application
        android:name=".App"
        ...
-       android:theme="@style/Theme.ToDometer.NoActionBar">
+       android:theme="@style/Theme.ToDometer.Starting">

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
axiel7commented, Aug 16, 2022

I solved this issue by calling DynamicColors.applyToActivityIfAvailable(this) after installSplashScreen(). Don’t use DynamicColors.applyToActivitiesIfAvailable(this) in your Application class.

override fun onCreate(savedInstanceState: Bundle?) {
        installSplashScreen()
        DynamicColors.applyToActivityIfAvailable(this)
        
}
1reaction
drchencommented, Feb 9, 2022

I don’t have access to your github link. Where do you call DynamicColors.applyToActivitiesIfAvailable(this) and installSplashScreen()?

You may want to avoid using postSplashScreenTheme since I guess it will override the dynamic color theme overlay we set. Or you can also try to set postSplashScreenTheme to ThemeOverlay.Material3.DynamicColors.DayNight and see if it works in your case?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I use dynamic colors in SplashScreen api an android ...
My problem wasn't that I cannot theme the splash screen, it was that I can not use the system dynamic colors (monet colors)...
Read more >
Migrate your existing splash screen implementation to Android ...
Once you migrate, the new API improves startup time, gives you full control over the splash screen experience, and ensures a more consistent...
Read more >
Implementing Core Splashscreen API | by Igor Escodro
If this step is not followed, the application will fail with: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or ...
Read more >
A Comprehensive Guide to Android 12's Splash Screen API
postSplashScreenTheme — This is used for defining the actual app theme you want to be used after the splash screen finishes. You should...
Read more >
Exploring Android 12: Splash Screen | Joe Birch
Now come Android 12, we have the new Splash Screen APIs. ... *I'm not entirely sure what color is being used for this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found