diff --git a/lib/java/com/google/android/material/appbar/AppBarLayout.java b/lib/java/com/google/android/material/appbar/AppBarLayout.java index 2c874729e83..38b762df5af 100644 --- a/lib/java/com/google/android/material/appbar/AppBarLayout.java +++ b/lib/java/com/google/android/material/appbar/AppBarLayout.java @@ -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 -> { @@ -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); } diff --git a/lib/java/com/google/android/material/color/MaterialColors.java b/lib/java/com/google/android/material/color/MaterialColors.java index cde74b5d299..56484495b90 100644 --- a/lib/java/com/google/android/material/color/MaterialColors.java +++ b/lib/java/com/google/android/material/color/MaterialColors.java @@ -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; } /**