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

  1. Make the app/activity theme inherit from Theme.MaterialComponents.<style> or Theme.Material3.<style> (check your material library version for which family applies).
  2. If full migration is not possible, use the Bridge themes: Theme.MaterialComponents.Bridge.* which keep AppCompat parents while supplying Material attributes.
  3. For component styles applied over non-Material themes, define materialThemeOverlay in the component's style pointing at ThemeOverlay.MaterialComponents.*.
  4. 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

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


AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14). Data as JSON: /api/errors/e5b57f833ccf0999. Report an issue: GitHub.