|
75 | 75 | import com.google.android.material.animation.AnimationUtils;
|
76 | 76 | import com.google.android.material.animation.ArgbEvaluatorCompat;
|
77 | 77 | import com.google.android.material.appbar.AppBarLayout.BaseBehavior.SavedState;
|
| 78 | +import com.google.android.material.color.MaterialColors; |
78 | 79 | import com.google.android.material.drawable.DrawableUtils;
|
79 | 80 | import com.google.android.material.internal.ThemeEnforcement;
|
80 | 81 | import com.google.android.material.motion.MotionUtils;
|
@@ -220,6 +221,7 @@ public interface LiftOnScrollListener {
|
220 | 221 | private int[] tmpStatesArray;
|
221 | 222 |
|
222 | 223 | @Nullable private Drawable statusBarForeground;
|
| 224 | + @Nullable private Integer statusBarForegroundOriginalColor; |
223 | 225 |
|
224 | 226 | private final float appBarElevation;
|
225 | 227 |
|
@@ -332,19 +334,29 @@ private void initializeLiftOnScrollWithColor(MaterialShapeDrawable background) {
|
332 | 334 | liftBackground.setAlpha(lifted ? 255 : 0);
|
333 | 335 | background.setAlpha(lifted ? 0 : 255);
|
334 | 336 |
|
| 337 | + ColorStateList colorSurface = |
| 338 | + MaterialColors.getColorStateListOrNull(getContext(), R.attr.colorSurface); |
| 339 | + |
335 | 340 | liftOnScrollColorUpdateListener =
|
336 | 341 | valueAnimator -> {
|
337 | 342 | float liftAlpha = (float) valueAnimator.getAnimatedValue();
|
338 | 343 | background.setAlpha((int) (255f - liftAlpha));
|
339 | 344 | liftBackground.setAlpha((int) liftAlpha);
|
340 | 345 |
|
| 346 | + int mixedColor = |
| 347 | + ArgbEvaluatorCompat.getInstance() |
| 348 | + .evaluate( |
| 349 | + liftAlpha / 255f, |
| 350 | + background.getResolvedTintColor(), |
| 351 | + liftBackground.getResolvedTintColor()); |
| 352 | + if (statusBarForeground != null |
| 353 | + && statusBarForegroundOriginalColor != null |
| 354 | + && colorSurface != null |
| 355 | + && statusBarForegroundOriginalColor == colorSurface.getDefaultColor()) { |
| 356 | + DrawableCompat.setTint(statusBarForeground, mixedColor); |
| 357 | + } |
| 358 | + |
341 | 359 | if (!liftOnScrollListeners.isEmpty()) {
|
342 |
| - int mixedColor = |
343 |
| - ArgbEvaluatorCompat.getInstance() |
344 |
| - .evaluate( |
345 |
| - liftAlpha / 255f, |
346 |
| - background.getResolvedTintColor(), |
347 |
| - liftBackground.getResolvedTintColor()); |
348 | 360 | for (LiftOnScrollListener liftOnScrollListener : liftOnScrollListeners) {
|
349 | 361 | if (background.getFillColor() != null) {
|
350 | 362 | liftOnScrollListener.onUpdate(0, mixedColor);
|
@@ -447,6 +459,7 @@ public void setStatusBarForeground(@Nullable Drawable drawable) {
|
447 | 459 | statusBarForeground.setCallback(null);
|
448 | 460 | }
|
449 | 461 | statusBarForeground = drawable != null ? drawable.mutate() : null;
|
| 462 | + statusBarForegroundOriginalColor = extractStatusBarForegroundColor(); |
450 | 463 | if (statusBarForeground != null) {
|
451 | 464 | if (statusBarForeground.isStateful()) {
|
452 | 465 | statusBarForeground.setState(getDrawableState());
|
@@ -497,6 +510,19 @@ public Drawable getStatusBarForeground() {
|
497 | 510 | return statusBarForeground;
|
498 | 511 | }
|
499 | 512 |
|
| 513 | + @Nullable |
| 514 | + private Integer extractStatusBarForegroundColor() { |
| 515 | + if (statusBarForeground instanceof MaterialShapeDrawable) { |
| 516 | + return ((MaterialShapeDrawable) statusBarForeground).getResolvedTintColor(); |
| 517 | + } |
| 518 | + ColorStateList statusBarForegroundColorStateList = |
| 519 | + DrawableUtils.getColorStateListOrNull(statusBarForeground); |
| 520 | + if (statusBarForegroundColorStateList != null) { |
| 521 | + return statusBarForegroundColorStateList.getDefaultColor(); |
| 522 | + } |
| 523 | + return null; |
| 524 | + } |
| 525 | + |
500 | 526 | @Override
|
501 | 527 | public void draw(@NonNull Canvas canvas) {
|
502 | 528 | super.draw(canvas);
|
|
0 commit comments