{"record":{"id":"73fef6be640e007f","repo":"material-components/material-components-android","slug":"the-style-on-this-component-requires-your-app-them","errorCode":null,"errorMessage":"The style on this component requires your app theme to be {} (or a descendant).","messagePattern":"The style on this component requires your app theme to be (.+?) \\(or a descendant\\)\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/internal/ThemeEnforcement.java","lineNumber":249,"sourceCode":"        .resolveBoolean(context, R.attr.isMaterial3Theme, false);\n  }\n\n  private static boolean isTheme(@NonNull Context context, @NonNull int[] themeAttributes) {\n    TypedArray a = context.obtainStyledAttributes(themeAttributes);\n    for (int i = 0; i < themeAttributes.length; i++) {\n      if (!a.hasValue(i)) {\n        a.recycle();\n        return false;\n      }\n    }\n    a.recycle();\n    return true;\n  }\n\n  private static void checkTheme(\n      @NonNull Context context, @NonNull int[] themeAttributes, String themeName) {\n    if (!isTheme(context, themeAttributes)) {\n      throw new IllegalArgumentException(\n          \"The style on this component requires your app theme to be \"\n              + themeName\n              + \" (or a descendant).\");\n    }\n  }\n}\n","sourceCodeStart":231,"sourceCodeEnd":256,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/internal/ThemeEnforcement.java#L231-L256","documentation":"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').","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set the affected activity/dialog theme's parent to the named theme (e.g. Theme.MaterialComponents.NoActionBar or Theme.Material3.*).","Use the corresponding .Bridge theme when you cannot fully migrate the parent chain.","Apply a materialThemeOverlay on the specific component's style so enforcement checks pass without changing the whole activity theme."],"exampleFix":"// before\n<style name=\"DialogTheme\" parent=\"Theme.AppCompat.Dialog\">\n  <!-- MaterialAlertDialog crashes: requires Theme.MaterialComponents -->\n</style>\n\n// after\n<style name=\"DialogTheme\" parent=\"Theme.MaterialComponents.Dialog.Alert\" />","handlingStrategy":"validation","validationCode":"int[] attrs = { R.attr.colorPrimary }; // the attributes the component enforces\nTypedArray a = context.getTheme().obtainStyledAttributes(attrs);\nboolean hasTheming = a.hasValue(0);\na.recycle();\nif (!hasTheming) throw new IllegalStateException(\"App theme is not a Material theme\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Inflate Material components only in Contexts whose theme is Material or Bridge.","Wrap non-Material contexts with ContextThemeWrapper(context, R.style.ThemeOverlay_MaterialComponents) before inflation.","Add a CI check that parses styles.xml parents for the required theme family."],"tags":["material-components","theme","inflation","material-theme"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}