Skip to content

Commit

Permalink
[AppBarLayout] Fix dynamic status bar foreground lift on scroll color…
Browse files Browse the repository at this point in the history
… when using Tonal Surface Color on API Level 33

Resolves #3530
Resolves #3585

PiperOrigin-RevId: 566609767
  • Loading branch information
dsn5ft committed Sep 19, 2023
1 parent 357cf2d commit c4ae01a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 2 additions & 4 deletions lib/java/com/google/android/material/appbar/AppBarLayout.java
Expand Up @@ -334,8 +334,7 @@ private void initializeLiftOnScrollWithColor(MaterialShapeDrawable background) {
liftBackground.setAlpha(lifted ? 255 : 0);
background.setAlpha(lifted ? 0 : 255);

ColorStateList colorSurface =
MaterialColors.getColorStateListOrNull(getContext(), R.attr.colorSurface);
Integer colorSurface = MaterialColors.getColorOrNull(getContext(), R.attr.colorSurface);

liftOnScrollColorUpdateListener =
valueAnimator -> {
Expand All @@ -351,8 +350,7 @@ private void initializeLiftOnScrollWithColor(MaterialShapeDrawable background) {
liftBackground.getResolvedTintColor());
if (statusBarForeground != null
&& statusBarForegroundOriginalColor != null
&& colorSurface != null
&& statusBarForegroundOriginalColor == colorSurface.getDefaultColor()) {
&& statusBarForegroundOriginalColor.equals(colorSurface)) {
DrawableCompat.setTint(statusBarForeground, mixedColor);
}

Expand Down
17 changes: 12 additions & 5 deletions lib/java/com/google/android/material/color/MaterialColors.java
Expand Up @@ -114,12 +114,19 @@ public static int getColor(
@ColorInt
public static int getColor(
@NonNull Context context, @AttrRes int colorAttributeResId, @ColorInt int defaultValue) {
Integer color = getColorOrNull(context, colorAttributeResId);
return color != null ? color : defaultValue;
}

/**
* Returns the color int for the provided theme color attribute, or null if the attribute is not
* set in the current theme.
*/
@Nullable
@ColorInt
public static Integer getColorOrNull(@NonNull Context context, @AttrRes int colorAttributeResId) {
TypedValue typedValue = MaterialAttributes.resolve(context, colorAttributeResId);
if (typedValue != null) {
return resolveColor(context, typedValue);
} else {
return defaultValue;
}
return typedValue != null ? resolveColor(context, typedValue) : null;
}

/**
Expand Down

0 comments on commit c4ae01a

Please sign in to comment.