material-components/material-components-android · error · IllegalArgumentException
This component requires that you specify a valid TextAppeara
Error message
This component requires that you specify a valid TextAppearance attribute. Update your app theme to inherit from Theme.MaterialComponents (or a descendant).
What it means
ThemeEnforcement checks, at view inflation time, that Material components get a valid android:textAppearance (or the component's own textAppearance attributes) from the theme. When a Material widget (e.g. MaterialButton, TextInputLayout, MaterialTextView) is inflated under a theme that is not Theme.MaterialComponents / Theme.Material3 (or Bridge), the required TextAppearance is absent and ThemeEnforcement throws IllegalArgumentException to make the theme mismatch obvious instead of rendering broken text metrics.
Source
Thrown at lib/java/com/google/android/material/internal/ThemeEnforcement.java:188
boolean validTextAppearance;
if (textAppearanceResIndices == null || textAppearanceResIndices.length == 0) {
// No custom TextAppearance attributes passed in, check android:textAppearance
validTextAppearance =
themeEnforcementAttrs.getResourceId(
R.styleable.ThemeEnforcement_android_textAppearance, -1)
!= -1;
} else {
// Check custom TextAppearances are valid
validTextAppearance =
isCustomTextAppearanceValid(
context, set, attrs, defStyleAttr, defStyleRes, textAppearanceResIndices);
}
themeEnforcementAttrs.recycle();
if (!validTextAppearance) {
throw new IllegalArgumentException(
"This component requires that you specify a valid TextAppearance attribute. Update your "
+ "app theme to inherit from Theme.MaterialComponents (or a descendant).");
}
}
private static boolean isCustomTextAppearanceValid(
@NonNull Context context,
AttributeSet set,
@NonNull @StyleableRes int[] attrs,
@AttrRes int defStyleAttr,
@StyleRes int defStyleRes,
@NonNull @StyleableRes int... textAppearanceResIndices) {
TypedArray componentAttrs =
context.obtainStyledAttributes(set, attrs, defStyleAttr, defStyleRes);
for (int customTextAppearanceIndex : textAppearanceResIndices) {
if (componentAttrs.getResourceId(customTextAppearanceIndex, -1) == -1) {
componentAttrs.recycle();
return false;View on GitHub (pinned to ac7e18efee)
Solutions
- Make the app/activity theme inherit from Theme.MaterialComponents.<style> or Theme.Material3.<style> (check your material library version for which family applies).
- If full migration is not possible, use the Bridge themes: Theme.MaterialComponents.Bridge.* which keep AppCompat parents while supplying Material attributes.
- For component styles applied over non-Material themes, define materialThemeOverlay in the component's style pointing at ThemeOverlay.MaterialComponents.*.
- Audit every <activity android:theme=...> and dialog theme in the manifest/layout roots for a non-Material parent.
Example fix
// before (styles.xml) <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar" /> <!-- MaterialButton inflation crashes with TextAppearance error --> // after <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar" /> <!-- or, to keep AppCompat parents: --> <style name="AppTheme" parent="Theme.MaterialComponents.Light.Bridge" />
Defensive patterns
Strategy: validation
Validate before calling
TypedValue tv = new TypedValue();
boolean ok = context.getTheme().resolveAttribute(android.R.attr.textAppearance, tv, true);
if (!ok) throw new IllegalStateException("Non-Material theme in use; check activity theme parent"); Prevention
- Set the application theme parent to Theme.MaterialComponents.* / Theme.Material3.* once, early in migration.
- Audit manifest activity/dialog themes for non-Material parents via lint or a CI grep.
- Use Bridge themes as an intermediate step for legacy screens.
When it happens
Trigger: Inflating Material components under Theme.AppCompat or a plain android theme; applying an activity/dialog theme that does not inherit from Theme.MaterialComponents/Theme.Material3; missing materialThemeOverlay in custom styles used with the component.
Common situations: Adding Material widgets to a legacy AppCompat project without migrating themes; a single Activity/Fragment/BOTTOM sheet using a custom theme that forgot the Material parent; library modules relying on the host app theme.
Related errors
- The style on this component requires your app theme to be {}
- %1$s requires a value for the %2$s attribute to be set in yo
- Invalid motion path type: > pathInt <
- Motion path theme attribute must either be an enum value or
- Invalid motion path type: > pathInt <
AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14).
Data as JSON: /api/errors/e5b57f833ccf0999.
Report an issue: GitHub.