{"record":{"id":"412c599b10be3324","repo":"material-components/material-components-android","slug":"setting-alpha-on-is-not-supported-412c59","errorCode":null,"errorMessage":"Setting alpha on is not supported","messagePattern":"Setting alpha on is not supported","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/transition/platform/MaterialContainerTransform.java","lineNumber":1342,"sourceCode":"            @Override\n            public void run(Canvas canvas) {\n              endView.draw(canvas);\n            }\n          });\n    }\n\n    private void maybeDrawContainerColor(Canvas canvas, Paint containerPaint) {\n      // Fill the container at the current layer with a color. Useful when the start or end view\n      // does not have a background or when the container size exceeds the image size which it can\n      // in large start/end size changes.\n      if (containerPaint.getColor() != Color.TRANSPARENT && containerPaint.getAlpha() > 0) {\n        canvas.drawRect(getBounds(), containerPaint);\n      }\n    }\n\n    @Override\n    public void setAlpha(int alpha) {\n      throw new UnsupportedOperationException(\"Setting alpha on is not supported\");\n    }\n\n    public void setColorFilter(@Nullable ColorFilter colorFilter) {\n      throw new UnsupportedOperationException(\"Setting a color filter is not supported\");\n    }\n\n    @Override\n    public int getOpacity() {\n      return PixelFormat.TRANSLUCENT;\n    }\n\n    private void setProgress(float progress) {\n      if (this.progress != progress) {\n        updateProgress(progress);\n      }\n    }\n\n    private void updateProgress(float progress) {","sourceCodeStart":1324,"sourceCodeEnd":1360,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/transition/platform/MaterialContainerTransform.java#L1324-L1360","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove android:requiresFadingEdge / android:fadingEdgeLength (and default fading edges) from the ScrollView/WebView/list that hosts the start or end view during the transform.","Disable drawing caches on the transformed views and their parents (setDrawingCacheEnabled(false), avoid android:cacheColorHint) for the duration of the transition.","Do not animate alpha (View.setAlpha / Fade) on any ancestor of the transformed views while the container transform is running.","Upgrade the Material Components library — later releases relaxed these Drawable overrides and fixed framework interaction crashes; check the release notes for your version.","If none apply, replace MaterialContainerTransform with a ChangeBounds + custom transition for that screen, since the drawable contract cannot be changed from app code."],"exampleFix":"// before (layout hosting the end view)\n<ScrollView xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android:requiresFadingEdge=\"vertical\"\n    android:fadingEdgeLength=\"8dp\">\n\n// after\n<ScrollView xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android:requiresFadingEdge=\"none\">","handlingStrategy":"validation","validationCode":"// Before starting the transform, make sure no fading edge / drawing cache\n// will force the framework to call setAlpha on the transform drawable.\nboolean safeForContainerTransform(View start, View end) {\n  for (View v = start; v != null; v = parentView(v)) {\n    if (v instanceof android.widget.ScrollView\n        || v instanceof android.widget.AbsListView\n        || v instanceof android.webkit.WebView) {\n      if (v instanceof android.view.View && v.isVerticalFadingEdgeEnabled()\n          || v.isHorizontalFadingEdgeEnabled()) {\n        return false;\n      }\n    }\n  }\n  return true; // apply the same loop for `end`\n}","typeGuard":null,"tryCatchPattern":"// Last-resort safety net around transition scheduling; a setAlpha crash here is\n// a bug in view config, so catch, report, and fall back to a plain transition.\ntry {\n  TransitionManager.beginDelayedTransition(root, materialContainerTransform);\n} catch (UnsupportedOperationException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Setting alpha\")) {\n    Crashlytics.log(Log.WARN, \"transform\", \"fading-edge/cache conflicted with transform\");\n    TransitionManager.beginDelayedTransition(root, new ChangeBounds()); // simple fallback\n  } else {\n    throw e;\n  }\n}","preventionTips":["Keep fading edges and cacheColorHint off any container hosting shared-element transform views.","Never animate alpha on ancestors of container-transformed views while the transform runs.","Test container transforms on screens with ScrollView, WebView, and RecyclerView roots.","Stay on a recent Material Components version; drawable/framework interaction fixes land regularly."],"tags":["android","material-components","transition","drawable","fragment"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}