From b84f35f1211028e7c456ce1ca91685a938f0ffcc Mon Sep 17 00:00:00 2001 From: dsn5ft <1420597+dsn5ft@users.noreply.github.com> Date: Wed, 19 Jan 2022 11:10:26 -0500 Subject: [PATCH] [Color] Update DynamicColors util to use activity.getTheme().applyStyle() instead of activity.setTheme() to workaround Force Dark issue Resolves https://github.com/material-components/material-components-android/issues/2521 PiperOrigin-RevId: 422816956 --- lib/java/com/google/android/material/color/DynamicColors.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/java/com/google/android/material/color/DynamicColors.java b/lib/java/com/google/android/material/color/DynamicColors.java index 9d7961d3831..21a69d92d28 100644 --- a/lib/java/com/google/android/material/color/DynamicColors.java +++ b/lib/java/com/google/android/material/color/DynamicColors.java @@ -231,7 +231,8 @@ private static void applyIfAvailable( theme = getDefaultThemeOverlay(activity); } if (theme != 0 && precondition.shouldApplyDynamicColors(activity, theme)) { - activity.setTheme(theme); + // Use applyStyle() instead of setTheme() due to Force Dark issue. + activity.getTheme().applyStyle(theme, /* force= */ true); } }