material-components/material-components-android · error · UnsupportedOperationException

Setting alpha on is not supported

Error message

Setting alpha on is not supported

What it means

MaterialContainerTransform draws its progress via a private Drawable (MaterialContainerTransform.java:1337) that overrides setAlpha to throw UnsupportedOperationException. The drawable's visuals are driven entirely by internal progress values and paints; delegating alpha to it would break the layered crossfade model, so the operation is deliberately unsupported rather than silently ignored.

Source

Thrown at lib/java/com/google/android/material/transition/MaterialContainerTransform.java:1337

            @Override
            public void run(Canvas canvas) {
              endView.draw(canvas);
            }
          });
    }

    private void maybeDrawContainerColor(Canvas canvas, Paint containerPaint) {
      // Fill the container at the current layer with a color. Useful when the start or end view
      // does not have a background or when the container size exceeds the image size which it can
      // in large start/end size changes.
      if (containerPaint.getColor() != Color.TRANSPARENT && containerPaint.getAlpha() > 0) {
        canvas.drawRect(getBounds(), containerPaint);
      }
    }

    @Override
    public void setAlpha(int alpha) {
      throw new UnsupportedOperationException("Setting alpha on is not supported");
    }

    public void setColorFilter(@Nullable ColorFilter colorFilter) {
      throw new UnsupportedOperationException("Setting a color filter is not supported");
    }

    @Override
    public int getOpacity() {
      return PixelFormat.TRANSLUCENT;
    }

    private void setProgress(float progress) {
      if (this.progress != progress) {
        updateProgress(progress);
      }
    }

    private void updateProgress(float progress) {

View on GitHub (pinned to ac7e18efee)

Solutions

  1. Do not call setAlpha on the transform's drawable; control appearance via MaterialContainerTransform's own API (progress, fadeMode, containerColor).
  2. In generic drawable-walking utilities, guard with a capability check (try a no-op probe or skip package-private drawables from material.transition).
  3. If you need custom alpha animation, wrap the transitioning views' alpha instead of the internal drawable.

Example fix

// before
for (Drawable d : overlay.getDrawables()) d.setAlpha(128); // crashes on transform drawable

// after
for (Drawable d : overlay.getDrawables()) {
  if (!(d instanceof MaterialContainerTransform drawableCompatMarker)) {
    d.setAlpha(128);
  }
}
// practically: filter by class name starting with "com.google.android.material.transition" or avoid touching internal drawables
Defensive patterns

Strategy: validation

Validate before calling

boolean isInternalTransformDrawable(Drawable d) {
  return d != null && d.getClass().getName().startsWith("com.google.android.material.transition");
}
// in any generic drawable walker:
if (!isInternalTransformDrawable(d)) d.setAlpha(alpha);

Try / catch

try { d.setAlpha(a); } catch (UnsupportedOperationException e) { /* drawable rejects alpha; skip */ } // acceptable in generic utilities only

Prevention

When it happens

Trigger: Obtaining the transition drawable (e.g. via the transform's view overlay during the animation) and calling setAlpha() on it; generic animation utilities that walk a hierarchy of drawables and call setAlpha on each; test code poking the drawable's Paint/alpha API surface.

Common situations: Custom scrubbing/debug tooling that manipulates drawables generically; reusing a drawable-inspection helper across all on-screen drawables while a container transform is running.

Related errors


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