Skip to content

Commit

Permalink
[Catalog][Menu] Fixes context menu are not themed on S
Browse files Browse the repository at this point in the history
On S, it seems like the framework has a different behavior of applying themes/styles on the decor view theme. Catalog's theme overlay applying logic didn't take care of the implication of the decor view theme, somehow this causes the Material themes are not applied to decor views at all, when a theme overlay is applied.

We've solved the similar issue with the dynamic color implementation. Applies the same fix on catalog to fix this issue.

Resolves #2682

PiperOrigin-RevId: 511254476
  • Loading branch information
drchen authored and hunterstich committed Feb 23, 2023
1 parent fd0c815 commit 33e4f84
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Expand Up @@ -20,6 +20,7 @@
import android.util.SparseIntArray;
import androidx.annotation.IdRes;
import androidx.annotation.StyleRes;
import com.google.android.material.color.ThemeUtils;

/** Utils for theme themeOverlays. */
public class ThemeOverlayUtils {
Expand Down Expand Up @@ -51,9 +52,10 @@ public static int getThemeOverlay(@IdRes int id) {
return themeOverlays.get(id);
}

@SuppressWarnings("RestrictTo")
public static void applyThemeOverlays(Activity activity) {
for (int i = 0; i < themeOverlays.size(); ++i) {
activity.setTheme(themeOverlays.valueAt(i));
ThemeUtils.applyThemeOverlay(activity, themeOverlays.valueAt(i));
}
}
}
16 changes: 13 additions & 3 deletions lib/java/com/google/android/material/color/ThemeUtils.java
Expand Up @@ -16,21 +16,31 @@

package com.google.android.material.color;

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources.Theme;
import android.view.View;
import android.view.Window;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.annotation.StyleRes;

/** Utility methods for theme. */
final class ThemeUtils {
// TODO(b/269781013): move this class to internal folder, which involves resolving cyclic dependency
// between color and internal folders
/**
* Utility methods for theme.
*
* @hide
*/
@RestrictTo(LIBRARY_GROUP)
public final class ThemeUtils {

private ThemeUtils() {}

static void applyThemeOverlay(@NonNull Context context, @StyleRes int theme) {
public static void applyThemeOverlay(@NonNull Context context, @StyleRes int theme) {
// Use applyStyle() instead of setTheme() due to Force Dark issue.
context.getTheme().applyStyle(theme, /* force= */ true);

Expand Down

0 comments on commit 33e4f84

Please sign in to comment.