{"record":{"id":"dea5990ab46d8eb2","repo":"Tencent/QMUI_Android","slug":"you-need-to-use-a-theme-appcompat-theme-or-descen","errorCode":null,"errorMessage":"You need to use a Theme.AppCompat theme (or descendant) with the design library.","messagePattern":"You need to use a Theme\\.AppCompat theme \\(or descendant\\) with the design library\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"qmui/src/main/java/com/qmuiteam/qmui/util/QMUIViewHelper.java","lineNumber":80,"sourceCode":" * @author cginechen\n * @date 2016-03-17\n */\npublic class QMUIViewHelper {\n\n    // copy from View.generateViewId for API <= 16\n    private static final AtomicInteger sNextGeneratedId = new AtomicInteger(1);\n\n\n    private static final int[] APPCOMPAT_CHECK_ATTRS = {\n            androidx.appcompat.R.attr.colorPrimary\n    };\n\n    public static void checkAppCompatTheme(Context context) {\n        TypedArray a = context.obtainStyledAttributes(APPCOMPAT_CHECK_ATTRS);\n        final boolean failed = !a.hasValue(0);\n        a.recycle();\n        if (failed) {\n            throw new IllegalArgumentException(\"You need to use a Theme.AppCompat theme \"\n                    + \"(or descendant) with the design library.\");\n        }\n    }\n\n    /**\n     * 获取activity的根view\n     */\n    public static View getActivityRoot(Activity activity) {\n        return ((ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT)).getChildAt(0);\n    }\n\n    /**\n     * 触发window的insets的广播，使得view的fitSystemWindows得以生效\n     */\n    @SuppressWarnings(\"deprecation\")\n    public static void requestApplyInsets(Window window) {\n        if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21) {\n            window.getDecorView().requestFitSystemWindows();","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/Tencent/QMUI_Android/blob/026e7d486677d6593a96689cd590ec3561176717/qmui/src/main/java/com/qmuiteam/qmui/util/QMUIViewHelper.java#L62-L98","documentation":"QMUIViewHelper.checkAppCompatTheme verifies that the context's theme defines the AppCompat flag attribute (APPCOMPAT_CHECK_ATTRS). If the attribute is missing, the activity/theme is not a Theme.AppCompat descendant, and the design library components would crash or render incorrectly, so an IllegalArgumentException is thrown.","triggerScenarios":"Using QMUI design-library components (e.g. bottom sheets, widgets backed by AppCompat) in an Activity whose theme does not inherit from Theme.AppCompat / Theme.MaterialComponents, e.g. android:Theme.Holo or a plain platform theme.","commonSituations":"Setting a non-AppCompat theme in AndroidManifest.xml for a specific activity, migrating an old app to the design library without updating styles.xml, or using a ContextThemeWrapper with the wrong base theme.","solutions":["Change the activity's theme in AndroidManifest.xml to one extending Theme.AppCompat (or Theme.MaterialComponents / DayNight).","Make your app theme's parent \"Theme.AppCompat.Light.DarkActionBar\" or similar.","If the activity intentionally isn't AppCompat, apply a ContextThemeWrapper with an AppCompat theme when creating the view.","Check styles.xml for themes accidentally declared with parent=\"android:Theme.*\" instead of \"Theme.AppCompat.*\"."],"exampleFix":"// before (AndroidManifest.xml)\n<activity android:name=\".MainActivity\" android:theme=\"@style/OldHoloTheme\" />\n// after (styles.xml + manifest)\n<style name=\"AppTheme\" parent=\"Theme.AppCompat.Light.NoActionBar\" />\n<activity android:name=\".MainActivity\" android:theme=\"@style/AppTheme\" />","handlingStrategy":"validation","validationCode":"TypedArray a = context.obtainStyledAttributes(\n        new int[]{R.attr.appcompat_flag_attr_placeholder});\nboolean ok = a.hasValue(0);\na.recycle();\nif (!ok) Log.e(TAG, \"Theme is not AppCompat; fix styles.xml before using QMUI design widgets\");","typeGuard":null,"tryCatchPattern":"try {\n    QMUIViewHelper.checkAppCompatTheme(context);\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(\"Set android:theme to a Theme.AppCompat descendant\", e);\n}","preventionTips":["Make every activity theme inherit from Theme.AppCompat / Theme.MaterialComponents / Theme.AppCompat.DayNight.","Check styles.xml parents use \"Theme.AppCompat.*\" not \"android:Theme.*\".","Keep the app-level theme AppCompat even for single-activity apps so shared contexts work.","When wrapping contexts (ContextThemeWrapper), always apply an AppCompat theme."],"tags":["android","qmui","theme","appcompat"],"backgroundTag":"invalid-config-value","analyzedSha":"026e7d486677d6593a96689cd590ec3561176717","analyzedAt":"2026-09-06T13:32:24.816Z","contentChangedAt":"2026-09-06T13:32:24.816Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}