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

Cannot set framework drawable as progress drawable.

Error message

Cannot set framework drawable as progress drawable.

What it means

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.

Source

Thrown at lib/java/com/google/android/material/progressindicator/BaseProgressIndicator.java:413

   * Sets a new progress drawable. It has to inherit from {@link DeterminateDrawable}.
   *
   * @param drawable The new progress drawable.
   * @throws IllegalArgumentException if a framework drawable is passed in.
   */
  @Override
  public void setProgressDrawable(@Nullable Drawable drawable) {
    if (drawable instanceof DeterminateDrawable) {
      DeterminateDrawable<S> determinateDrawable = (DeterminateDrawable<S>) drawable;
      determinateDrawable.hideNow();
      super.setProgressDrawable(determinateDrawable);
      // Every time ProgressBar sets progress drawable, it refreshes the drawable's level with
      // progress then secondary progress. Since secondary progress is not used here. We need to set
      // the level actively to overcome the affects from secondary progress.
      determinateDrawable.setLevelByFraction((float) getProgress() / getMax());
    } else if (!initialized) {
      super.setProgressDrawable(drawable);
    } else {
      throw new IllegalArgumentException("Cannot set framework drawable as progress drawable.");
    }
  }

  /**
   * Sets a new indeterminate drawable. It has to inherit from {@link IndeterminateDrawable}.
   *
   * @param drawable The new indeterminate drawable.
   * @throws IllegalArgumentException if a framework drawable is passed in.
   */
  @Override
  public void setIndeterminateDrawable(@Nullable Drawable drawable) {
    if (drawable instanceof IndeterminateDrawable) {
      ((DrawableWithAnimatedVisibilityChange) drawable).hideNow();
      super.setIndeterminateDrawable(drawable);
    } else if (!initialized) {
      super.setIndeterminateDrawable(drawable);
    } else {
      throw new IllegalArgumentException(

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Do not override the progress drawable; style the indicator via its attributes (indicatorColor, trackColor, trackCornerRadius, etc.)
  2. If a custom drawable is required, ensure it is a DeterminateDrawable created for this indicator type
  3. Use a plain ProgressBar/LinearProgressIndicator from the framework if a fully custom drawable is the goal

Example fix

<!-- before -->
<com.google.android.material.progressindicator.LinearProgressIndicator
    android:progressDrawable="@drawable/custom_clip_progress" ... />
<!-- after -->
<com.google.android.material.progressindicator.LinearProgressIndicator
    app:indicatorColor="@color/brand" app:trackColor="@color/track" ... />
Defensive patterns

Strategy: type-guard

Type guard

fun isSafeProgressDrawable(d: Drawable?, indicator: BaseProgressIndicator<*>): Boolean =
    d is DeterminateDrawable<*> || !indicator.isInitialized

Try / catch

catch (e: IllegalArgumentException) { Log.e(TAG, "Rejected framework progress drawable; styling via spec instead", e) }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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