From 7674e12ea818793fe654f7691941f0bdc97c75f3 Mon Sep 17 00:00:00 2001 From: pubiqq Date: Thu, 2 Nov 2023 13:58:38 +0000 Subject: [PATCH] [CollapsingToolbarLayout] Fix text shadow fading when transitioning between expanded and collapsed states Resolves https://github.com/material-components/material-components-android/pull/3641 GIT_ORIGIN_REV_ID=7243f7a2f09b04caceec488443b1652a8ffef961 PiperOrigin-RevId: 578838845 --- .../android/material/internal/CollapsingTextHelper.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/java/com/google/android/material/internal/CollapsingTextHelper.java b/lib/java/com/google/android/material/internal/CollapsingTextHelper.java index 5194ed8ec72..fa200df1292 100644 --- a/lib/java/com/google/android/material/internal/CollapsingTextHelper.java +++ b/lib/java/com/google/android/material/internal/CollapsingTextHelper.java @@ -672,6 +672,14 @@ private void calculateOffsets(final float fraction) { int textAlpha = (int) (calculateFadeModeTextAlpha(fraction) * originalAlpha); textPaint.setAlpha(textAlpha); + // Workaround for API 31(+). Applying the shadow color for the painted text. + if (VERSION.SDK_INT >= VERSION_CODES.S) { + textPaint.setShadowLayer( + currentShadowRadius, + currentShadowDx, + currentShadowDy, + MaterialColors.compositeARGBWithAlpha(currentShadowColor, textPaint.getAlpha())); + } } ViewCompat.postInvalidateOnAnimation(view);