{"record":{"id":"f7733d5503882277","repo":"material-components/material-components-android","slug":"cannot-set-framework-drawable-as-progress-drawable","errorCode":null,"errorMessage":"Cannot set framework drawable as progress drawable.","messagePattern":"Cannot set framework drawable as progress drawable\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/progressindicator/BaseProgressIndicator.java","lineNumber":413,"sourceCode":"   * Sets a new progress drawable. It has to inherit from {@link DeterminateDrawable}.\n   *\n   * @param drawable The new progress drawable.\n   * @throws IllegalArgumentException if a framework drawable is passed in.\n   */\n  @Override\n  public void setProgressDrawable(@Nullable Drawable drawable) {\n    if (drawable instanceof DeterminateDrawable) {\n      DeterminateDrawable<S> determinateDrawable = (DeterminateDrawable<S>) drawable;\n      determinateDrawable.hideNow();\n      super.setProgressDrawable(determinateDrawable);\n      // Every time ProgressBar sets progress drawable, it refreshes the drawable's level with\n      // progress then secondary progress. Since secondary progress is not used here. We need to set\n      // the level actively to overcome the affects from secondary progress.\n      determinateDrawable.setLevelByFraction((float) getProgress() / getMax());\n    } else if (!initialized) {\n      super.setProgressDrawable(drawable);\n    } else {\n      throw new IllegalArgumentException(\"Cannot set framework drawable as progress drawable.\");\n    }\n  }\n\n  /**\n   * Sets a new indeterminate drawable. It has to inherit from {@link IndeterminateDrawable}.\n   *\n   * @param drawable The new indeterminate drawable.\n   * @throws IllegalArgumentException if a framework drawable is passed in.\n   */\n  @Override\n  public void setIndeterminateDrawable(@Nullable Drawable drawable) {\n    if (drawable instanceof IndeterminateDrawable) {\n      ((DrawableWithAnimatedVisibilityChange) drawable).hideNow();\n      super.setIndeterminateDrawable(drawable);\n    } else if (!initialized) {\n      super.setIndeterminateDrawable(drawable);\n    } else {\n      throw new IllegalArgumentException(","sourceCodeStart":395,"sourceCodeEnd":431,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/progressindicator/BaseProgressIndicator.java#L395-L431","documentation":"BaseProgressIndicator.setProgressDrawable requires a DeterminateDrawable once the indicator is initialized; framework ProgressBar drawables are rejected with IllegalArgumentException because they cannot render Material's animated show/hide and level-based progress. Before initialization (during super constructor), any drawable passes through for ProgressBar internals.","triggerScenarios":"Calling setProgressDrawable(myDrawable) on an initialized LinearProgressIndicator/CircularProgressIndicator where the drawable is not a DeterminateDrawable; e.g. setting a ClipDrawable or LayerDrawable from XML-typical progress code.","commonSituations":"Porting plain ProgressBar code (custom progress drawables) to Material's progress indicator; XML android:progressDrawable resolving to a non-Determinate drawable on a Material indicator; calling setProgressDrawable(DeterminateDrawable.createFrom(...)) incorrectly typed.","solutions":["Do not override the progress drawable; style the indicator via its attributes (indicatorColor, trackColor, trackCornerRadius, etc.)","If a custom drawable is required, ensure it is a DeterminateDrawable created for this indicator type","Use a plain ProgressBar/LinearProgressIndicator from the framework if a fully custom drawable is the goal"],"exampleFix":"<!-- before -->\n<com.google.android.material.progressindicator.LinearProgressIndicator\n    android:progressDrawable=\"@drawable/custom_clip_progress\" ... />\n<!-- after -->\n<com.google.android.material.progressindicator.LinearProgressIndicator\n    app:indicatorColor=\"@color/brand\" app:trackColor=\"@color/track\" ... />","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"fun isSafeProgressDrawable(d: Drawable?, indicator: BaseProgressIndicator<*>): Boolean =\n    d is DeterminateDrawable<*> || !indicator.isInitialized","tryCatchPattern":"catch (e: IllegalArgumentException) { Log.e(TAG, \"Rejected framework progress drawable; styling via spec instead\", e) }","preventionTips":["Never set custom progress drawables on Material progress indicators","Customize appearance with indicator/track attributes and the spec API","Use a plain ProgressBar when custom drawables are required"],"tags":["android","material-components","progressindicator","drawable"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}