Skip to content

Commit 1a31ddc

Browse files
committed
Fix AppBarLayout statusBarForeground issue where status bar drawable is drawn behind content
Resolves #824 PiperOrigin-RevId: 285981837 (cherry picked from commit 2059499)
1 parent 904d063 commit 1a31ddc

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ public void setStatusBarForeground(@Nullable Drawable drawable) {
333333
statusBarForeground.setVisible(getVisibility() == VISIBLE, false);
334334
statusBarForeground.setCallback(this);
335335
}
336+
updateWillNotDraw();
336337
ViewCompat.postInvalidateOnAnimation(this);
337338
}
338339
}
@@ -379,7 +380,7 @@ public void draw(@NonNull Canvas canvas) {
379380
super.draw(canvas);
380381

381382
// Draw the status bar foreground drawable if we have a top inset
382-
if (statusBarForeground != null && getTopInset() > 0) {
383+
if (shouldDrawStatusBarForeground()) {
383384
int saveCount = canvas.save();
384385
canvas.translate(0f, -currentOffset);
385386
statusBarForeground.draw(canvas);
@@ -480,6 +481,14 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
480481
}
481482
}
482483

484+
private void updateWillNotDraw() {
485+
setWillNotDraw(!shouldDrawStatusBarForeground());
486+
}
487+
488+
private boolean shouldDrawStatusBarForeground() {
489+
return statusBarForeground != null && getTopInset() > 0;
490+
}
491+
483492
private boolean hasCollapsibleChild() {
484493
for (int i = 0, z = getChildCount(); i < z; i++) {
485494
if (((LayoutParams) getChildAt(i).getLayoutParams()).isCollapsible()) {
@@ -981,6 +990,7 @@ WindowInsetsCompat onWindowInsetChanged(final WindowInsetsCompat insets) {
981990
// If our insets have changed, keep them and trigger a layout...
982991
if (!ObjectsCompat.equals(lastInsets, newInsets)) {
983992
lastInsets = newInsets;
993+
updateWillNotDraw();
984994
requestLayout();
985995
}
986996

0 commit comments

Comments
 (0)