Skip to content

Commit c4ae01a

Browse files
committedSep 19, 2023
[AppBarLayout] Fix dynamic status bar foreground lift on scroll color when using Tonal Surface Color on API Level 33
Resolves #3530 Resolves #3585 PiperOrigin-RevId: 566609767
1 parent 357cf2d commit c4ae01a

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed
 

‎lib/java/com/google/android/material/appbar/AppBarLayout.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,7 @@ private void initializeLiftOnScrollWithColor(MaterialShapeDrawable background) {
334334
liftBackground.setAlpha(lifted ? 255 : 0);
335335
background.setAlpha(lifted ? 0 : 255);
336336

337-
ColorStateList colorSurface =
338-
MaterialColors.getColorStateListOrNull(getContext(), R.attr.colorSurface);
337+
Integer colorSurface = MaterialColors.getColorOrNull(getContext(), R.attr.colorSurface);
339338

340339
liftOnScrollColorUpdateListener =
341340
valueAnimator -> {
@@ -351,8 +350,7 @@ private void initializeLiftOnScrollWithColor(MaterialShapeDrawable background) {
351350
liftBackground.getResolvedTintColor());
352351
if (statusBarForeground != null
353352
&& statusBarForegroundOriginalColor != null
354-
&& colorSurface != null
355-
&& statusBarForegroundOriginalColor == colorSurface.getDefaultColor()) {
353+
&& statusBarForegroundOriginalColor.equals(colorSurface)) {
356354
DrawableCompat.setTint(statusBarForeground, mixedColor);
357355
}
358356

‎lib/java/com/google/android/material/color/MaterialColors.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,19 @@ public static int getColor(
114114
@ColorInt
115115
public static int getColor(
116116
@NonNull Context context, @AttrRes int colorAttributeResId, @ColorInt int defaultValue) {
117+
Integer color = getColorOrNull(context, colorAttributeResId);
118+
return color != null ? color : defaultValue;
119+
}
120+
121+
/**
122+
* Returns the color int for the provided theme color attribute, or null if the attribute is not
123+
* set in the current theme.
124+
*/
125+
@Nullable
126+
@ColorInt
127+
public static Integer getColorOrNull(@NonNull Context context, @AttrRes int colorAttributeResId) {
117128
TypedValue typedValue = MaterialAttributes.resolve(context, colorAttributeResId);
118-
if (typedValue != null) {
119-
return resolveColor(context, typedValue);
120-
} else {
121-
return defaultValue;
122-
}
129+
return typedValue != null ? resolveColor(context, typedValue) : null;
123130
}
124131

125132
/**

0 commit comments

Comments
 (0)
Please sign in to comment.