@@ -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