material-components/material-components-android · error · IllegalArgumentException

The style on this component requires your app theme to be {}

Error message

The style on this component requires your app theme to be {} (or a descendant).

What it means

ThemeEnforcement.checkTheme verifies that the inflated component's theme resolves a required set of theme attributes (e.g. themeAttributeList declared via the component's enforceMaterialTheme styleable). If the app theme does not define them — i.e. it is not the required Material theme or a descendant — it throws IllegalArgumentException naming the required theme (the {} placeholder is filled with e.g. 'Theme.MaterialComponents').

Source

Thrown at lib/java/com/google/android/material/internal/ThemeEnforcement.java:249

        .resolveBoolean(context, R.attr.isMaterial3Theme, false);
  }

  private static boolean isTheme(@NonNull Context context, @NonNull int[] themeAttributes) {
    TypedArray a = context.obtainStyledAttributes(themeAttributes);
    for (int i = 0; i < themeAttributes.length; i++) {
      if (!a.hasValue(i)) {
        a.recycle();
        return false;
      }
    }
    a.recycle();
    return true;
  }

  private static void checkTheme(
      @NonNull Context context, @NonNull int[] themeAttributes, String themeName) {
    if (!isTheme(context, themeAttributes)) {
      throw new IllegalArgumentException(
          "The style on this component requires your app theme to be "
              + themeName
              + " (or a descendant).");
    }
  }
}

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Set the affected activity/dialog theme's parent to the named theme (e.g. Theme.MaterialComponents.NoActionBar or Theme.Material3.*).
  2. Use the corresponding .Bridge theme when you cannot fully migrate the parent chain.
  3. Apply a materialThemeOverlay on the specific component's style so enforcement checks pass without changing the whole activity theme.

Example fix

// before
<style name="DialogTheme" parent="Theme.AppCompat.Dialog">
  <!-- MaterialAlertDialog crashes: requires Theme.MaterialComponents -->
</style>

// after
<style name="DialogTheme" parent="Theme.MaterialComponents.Dialog.Alert" />
Defensive patterns

Strategy: validation

Validate before calling

int[] attrs = { R.attr.colorPrimary }; // the attributes the component enforces
TypedArray a = context.getTheme().obtainStyledAttributes(attrs);
boolean hasTheming = a.hasValue(0);
a.recycle();
if (!hasTheming) throw new IllegalStateException("App theme is not a Material theme");

Prevention

When it happens

Trigger: Inflating widgets that declare enforceMaterialTheme (e.g. MaterialToolbar, MaterialAlertDialog window themes, tabs) under Theme.AppCompat or platform themes; using a dialog theme whose parent is not the required Material theme.

Common situations: Legacy AppCompat apps incrementally adopting Material components; third-party libraries that inflate Material views inside the host app's non-Material theme; theming only some Activities.

Related errors


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