@@ -50,19 +50,44 @@ private MaterialThemeOverlay() {}
50
50
private static final int [] MATERIAL_THEME_OVERLAY_ATTR = new int [] {R .attr .materialThemeOverlay };
51
51
52
52
/**
53
- * Uses the materialThemeOverlay attribute to create a themed context. This allows us to use
54
- * MaterialThemeOverlay with a default style, and gives us some protection against losing our
55
- * ThemeOverlay by clients who set android:theme or app:theme. If android:theme or app:theme is
56
- * specified by the client, any attributes defined there will take precedence over attributes
57
- * defined in materialThemeOverlay.
53
+ * Uses the materialThemeOverlay attribute to create a themed context.
54
+ *
55
+ * <p>This allows us to use MaterialThemeOverlay with a default style, and gives us some
56
+ * protection against losing our ThemeOverlay by clients who set android:theme or app:theme.
57
+ * If android:theme or app:theme is specified by the client, any attributes defined there
58
+ * will take precedence over attributes defined in materialThemeOverlay.
59
+ */
60
+ @ NonNull
61
+ public static Context wrap (
62
+ @ NonNull Context context ,
63
+ @ Nullable AttributeSet set ,
64
+ @ AttrRes int defStyleAttr ,
65
+ @ StyleRes int defStyleRes ) {
66
+ return wrap (context , set , defStyleAttr , defStyleRes , new int [] {});
67
+ }
68
+
69
+ /**
70
+ * Uses the materialThemeOverlay attribute and optionalAttr attributes to create a combined
71
+ * themed context.
72
+ *
73
+ * <p>The final theme overlay will apply materialThemeOverlay first, then the optionalAttr
74
+ * overlays in order.
75
+ *
76
+ * <p>This facilitates creating locally scoped, re-usable overlays for component variants. For
77
+ * example, if buttons can be one of two colors and one of three shapes, instead of creating a
78
+ * style for each color-shape combination, an overlay can be created for each color and
79
+ * each shape. The button can then wrap its context and pass both overlay attributes to
80
+ * optionalAttrs before reading color and shape values.
81
+ *
82
+ * @see #wrap(Context, AttributeSet, int, int)
58
83
*/
59
84
@ NonNull
60
85
public static Context wrap (
61
86
@ NonNull Context context ,
62
87
@ Nullable AttributeSet set ,
63
88
@ AttrRes int defStyleAttr ,
64
89
@ StyleRes int defStyleRes ,
65
- @ NonNull int ... optionalAttrs ) {
90
+ @ NonNull int [] optionalAttrs ) {
66
91
int materialThemeOverlayId =
67
92
obtainMaterialThemeOverlayId (context , set , defStyleAttr , defStyleRes );
68
93
boolean contextHasOverlay =
0 commit comments