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-colored container via a private Drawable (a ColorDrawable subclass) that renders with its own Paint whose alpha/color are driven by transition progress. Because the drawable's appearance must stay in sync with the transform, its setAlpha(int) override deliberately throws UnsupportedOperationException instead of applying the alpha. The framework (not your code) can invoke setAlpha on any drawable attached to a View, for example when the view is inside a scrolling/fading-edge container or when the view's drawing is composited through a drawing cache or a semi-transparent layer.

Source

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

            @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. Remove android:requiresFadingEdge / android:fadingEdgeLength (and default fading edges) from the ScrollView/WebView/list that hosts the start or end view during the transform.
  2. Disable drawing caches on the transformed views and their parents (setDrawingCacheEnabled(false), avoid android:cacheColorHint) for the duration of the transition.
  3. Do not animate alpha (View.setAlpha / Fade) on any ancestor of the transformed views while the container transform is running.
  4. Upgrade the Material Components library — later releases relaxed these Drawable overrides and fixed framework interaction crashes; check the release notes for your version.
  5. If none apply, replace MaterialContainerTransform with a ChangeBounds + custom transition for that screen, since the drawable contract cannot be changed from app code.

Example fix

// before (layout hosting the end view)
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:requiresFadingEdge="vertical"
    android:fadingEdgeLength="8dp">

// after
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:requiresFadingEdge="none">
Defensive patterns

Strategy: validation

Validate before calling

// Before starting the transform, make sure no fading edge / drawing cache
// will force the framework to call setAlpha on the transform drawable.
boolean safeForContainerTransform(View start, View end) {
  for (View v = start; v != null; v = parentView(v)) {
    if (v instanceof android.widget.ScrollView
        || v instanceof android.widget.AbsListView
        || v instanceof android.webkit.WebView) {
      if (v instanceof android.view.View && v.isVerticalFadingEdgeEnabled()
          || v.isHorizontalFadingEdgeEnabled()) {
        return false;
      }
    }
  }
  return true; // apply the same loop for `end`
}

Try / catch

// Last-resort safety net around transition scheduling; a setAlpha crash here is
// a bug in view config, so catch, report, and fall back to a plain transition.
try {
  TransitionManager.beginDelayedTransition(root, materialContainerTransform);
} catch (UnsupportedOperationException e) {
  if (e.getMessage() != null && e.getMessage().contains("Setting alpha")) {
    Crashlytics.log(Log.WARN, "transform", "fading-edge/cache conflicted with transform");
    TransitionManager.beginDelayedTransition(root, new ChangeBounds()); // simple fallback
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: Running a MaterialContainerTransform (e.g., as a shared-element transition on a Fragment or via TransitionManager.beginDelayedTransition) where the start or end view participates in an Android framework code path that calls Drawable.setAlpha: a ScrollView/WebView/NestedScrollView with android:requiresFadingEdge (fading edges render children into a drawable and call setAlpha on it), an ancestor with android:cacheColorHint or a manual drawing cache (view.setDrawingCacheEnabled), or a cross-fade/View.setAlpha animation applied to a parent that contains the transformed view.

Common situations: Fragment shared-element container transform onto a screen whose root is a ScrollView or WebView with fading edges; listing views with cacheColorHint; wrapping the transition target in a ViewOverlay while an alpha animation runs; using TransitionSets that mix Fade with MaterialContainerTransform on overlapping views.

Related errors


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