Skip to content

Unable to apply DynamicColors in conjunction with AppCompatDelegate.setDefaultNightMode() #3366

Open
@bubbleguuum

Description

@bubbleguuum

Material version: 1.9.0-rc01
Tested on Pixel 4a, Android 13

My app theme is a custom theme whose parent is Theme.Material3.DynamicColors.DayNight

I can use the DynamicColors api just fine to apply it globally in my Application's onCreate():

DynamicColors.applyToActivitiesIfAvailable(this, new DynamicColorsOptions.Builder()build());

With this, the dynamic colors (Material You) are applied.

However, If I use AppCompatDelegate.setDefaultNightMode() (called before of after the applyToActivitiesIfAvailable() call, it does not matter) to force dark mode on or off (depending of app setting),
the dynamic colors are not applied and the theme is using whatever default colors are configured for non dynamic mode (purple in my case, the default M3 color scheme, since I did not define custom colors in my theme yet).

After some digging into it, I see that a call AppCompatDelegate.setDefaultNightMode() results in some heavy stuff being done in the activity's attachbaseContext() which is called prior the DynamicColors's onActivityPreCreated() hook.

Apparently these 2 things conflict with each other. Or am I doing something wrong ? AppCompatDelegate.setDefaultNightMode() is otherwise working fine outside of being used with DynamycColors.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions