|
34 | 34 | import android.graphics.Canvas;
|
35 | 35 | import android.graphics.Rect;
|
36 | 36 | import android.graphics.drawable.ColorDrawable;
|
37 |
| -import android.graphics.drawable.ColorStateListDrawable; |
38 | 37 | import android.graphics.drawable.Drawable;
|
39 | 38 | import android.graphics.drawable.LayerDrawable;
|
40 | 39 | import android.os.Build;
|
|
53 | 52 | import android.widget.ScrollView;
|
54 | 53 | import androidx.annotation.ColorInt;
|
55 | 54 | import androidx.annotation.Dimension;
|
56 |
| -import androidx.annotation.DoNotInline; |
57 | 55 | import androidx.annotation.DrawableRes;
|
58 | 56 | import androidx.annotation.IdRes;
|
59 | 57 | import androidx.annotation.IntDef;
|
|
77 | 75 | import com.google.android.material.animation.AnimationUtils;
|
78 | 76 | import com.google.android.material.animation.ArgbEvaluatorCompat;
|
79 | 77 | import com.google.android.material.appbar.AppBarLayout.BaseBehavior.SavedState;
|
| 78 | +import com.google.android.material.drawable.DrawableUtils; |
80 | 79 | import com.google.android.material.internal.ThemeEnforcement;
|
81 | 80 | import com.google.android.material.motion.MotionUtils;
|
82 | 81 | import com.google.android.material.resources.MaterialResources;
|
@@ -262,10 +261,11 @@ public AppBarLayout(@NonNull Context context, @Nullable AttributeSet attrs, int
|
262 | 261 | MaterialResources.getColorStateList(
|
263 | 262 | context, a, R.styleable.AppBarLayout_liftOnScrollColor);
|
264 | 263 |
|
265 |
| - ColorStateList backgroundCSL = getBackgroundCSL(); |
266 |
| - if (backgroundCSL != null) { |
| 264 | + ColorStateList backgroundColorStateList = |
| 265 | + DrawableUtils.getColorStateListOrNull(getBackground()); |
| 266 | + if (backgroundColorStateList != null) { |
267 | 267 | MaterialShapeDrawable materialShapeDrawable = new MaterialShapeDrawable();
|
268 |
| - materialShapeDrawable.setFillColor(backgroundCSL); |
| 268 | + materialShapeDrawable.setFillColor(backgroundColorStateList); |
269 | 269 | // If there is a lift on scroll color specified, we do not initialize the elevation overlay
|
270 | 270 | // and set the alpha to zero manually.
|
271 | 271 | if (liftOnScrollColor != null) {
|
@@ -326,17 +326,6 @@ public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets)
|
326 | 326 | });
|
327 | 327 | }
|
328 | 328 |
|
329 |
| - @Nullable |
330 |
| - private ColorStateList getBackgroundCSL() { |
331 |
| - Drawable background = getBackground(); |
332 |
| - if (background instanceof ColorDrawable) { |
333 |
| - return ColorStateList.valueOf(((ColorDrawable) background).getColor()); |
334 |
| - } else if (VERSION.SDK_INT >= VERSION_CODES.Q) { |
335 |
| - return DrawableHelperV29.maybeGetBackgroundCSL(background); |
336 |
| - } |
337 |
| - return null; |
338 |
| - } |
339 |
| - |
340 | 329 | private void initializeLiftOnScrollWithColor(MaterialShapeDrawable background) {
|
341 | 330 | MaterialShapeDrawable liftBackground = new MaterialShapeDrawable();
|
342 | 331 | liftBackground.setFillColor(liftOnScrollColor);
|
@@ -2612,16 +2601,4 @@ public void onOffsetChanged(
|
2612 | 2601 | }
|
2613 | 2602 | }
|
2614 | 2603 | }
|
2615 |
| - |
2616 |
| - @RequiresApi(VERSION_CODES.Q) |
2617 |
| - private static class DrawableHelperV29 { |
2618 |
| - @DoNotInline |
2619 |
| - @Nullable |
2620 |
| - private static ColorStateList maybeGetBackgroundCSL(@Nullable Drawable background) { |
2621 |
| - if (background instanceof ColorStateListDrawable) { |
2622 |
| - return ((ColorStateListDrawable) background).getColorStateList(); |
2623 |
| - } |
2624 |
| - return null; |
2625 |
| - } |
2626 |
| - } |
2627 | 2604 | }
|
0 commit comments