{"record":{"id":"e5b57f833ccf0999","repo":"material-components/material-components-android","slug":"this-component-requires-that-you-specify-a-valid-t","errorCode":null,"errorMessage":"This component requires that you specify a valid TextAppearance attribute. Update your app theme to inherit from Theme.MaterialComponents (or a descendant).","messagePattern":"This component requires that you specify a valid TextAppearance attribute\\. Update your app theme to inherit from Theme\\.MaterialComponents \\(or a descendant\\)\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/internal/ThemeEnforcement.java","lineNumber":188,"sourceCode":"    boolean validTextAppearance;\n\n    if (textAppearanceResIndices == null || textAppearanceResIndices.length == 0) {\n      // No custom TextAppearance attributes passed in, check android:textAppearance\n      validTextAppearance =\n          themeEnforcementAttrs.getResourceId(\n                  R.styleable.ThemeEnforcement_android_textAppearance, -1)\n              != -1;\n    } else {\n      // Check custom TextAppearances are valid\n      validTextAppearance =\n          isCustomTextAppearanceValid(\n              context, set, attrs, defStyleAttr, defStyleRes, textAppearanceResIndices);\n    }\n\n    themeEnforcementAttrs.recycle();\n\n    if (!validTextAppearance) {\n      throw new IllegalArgumentException(\n          \"This component requires that you specify a valid TextAppearance attribute. Update your \"\n              + \"app theme to inherit from Theme.MaterialComponents (or a descendant).\");\n    }\n  }\n\n  private static boolean isCustomTextAppearanceValid(\n      @NonNull Context context,\n      AttributeSet set,\n      @NonNull @StyleableRes int[] attrs,\n      @AttrRes int defStyleAttr,\n      @StyleRes int defStyleRes,\n      @NonNull @StyleableRes int... textAppearanceResIndices) {\n    TypedArray componentAttrs =\n        context.obtainStyledAttributes(set, attrs, defStyleAttr, defStyleRes);\n    for (int customTextAppearanceIndex : textAppearanceResIndices) {\n      if (componentAttrs.getResourceId(customTextAppearanceIndex, -1) == -1) {\n        componentAttrs.recycle();\n        return false;","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/internal/ThemeEnforcement.java#L170-L206","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (styles.xml)\n<style name=\"AppTheme\" parent=\"Theme.AppCompat.Light.DarkActionBar\" />\n<!-- MaterialButton inflation crashes with TextAppearance error -->\n\n// after\n<style name=\"AppTheme\" parent=\"Theme.MaterialComponents.Light.DarkActionBar\" />\n<!-- or, to keep AppCompat parents: -->\n<style name=\"AppTheme\" parent=\"Theme.MaterialComponents.Light.Bridge\" />","handlingStrategy":"validation","validationCode":"TypedValue tv = new TypedValue();\nboolean ok = context.getTheme().resolveAttribute(android.R.attr.textAppearance, tv, true);\nif (!ok) throw new IllegalStateException(\"Non-Material theme in use; check activity theme parent\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["material-components","theme","textappearance","inflation"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}