mirror of
https://github.com/material-components/material-components-android.git
synced 2026-02-20 08:39:55 +08:00
Update ThemeEnforcement context to read only the android:theme attribute from the style
PiperOrigin-RevId: 206313825
This commit is contained in:
parent
ffa7b10cae
commit
6f714ecc4f
@ -231,10 +231,6 @@ public final class ThemeEnforcement {
|
||||
* defStyleAttr to use a theme overlay if one has been defined.
|
||||
*/
|
||||
public static Context createThemedContext(Context context, int defStyleAttr) {
|
||||
if (context instanceof ContextThemeWrapper) {
|
||||
return context;
|
||||
}
|
||||
|
||||
TypedArray a = context.getTheme().obtainStyledAttributes(new int[] {defStyleAttr});
|
||||
int style = a.getResourceId(0 /* index */, 0 /* defaultVal */);
|
||||
a.recycle();
|
||||
@ -244,6 +240,16 @@ public final class ThemeEnforcement {
|
||||
return context;
|
||||
}
|
||||
|
||||
return new ContextThemeWrapper(context, style);
|
||||
a = context.obtainStyledAttributes(style, new int[] {android.R.attr.theme});
|
||||
int themeId = a.getResourceId(0 /* index */, 0 /* defaultVal */);
|
||||
a.recycle();
|
||||
|
||||
if (themeId != 0 && (!(context instanceof ContextThemeWrapper)
|
||||
|| ((ContextThemeWrapper) context).getThemeResId() != themeId)) {
|
||||
// If the context isn't a ContextThemeWrapper, or it is but does not have
|
||||
// the same theme as we need, wrap it in a new wrapper
|
||||
context = new ContextThemeWrapper(context, themeId);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user