Skip to content

Commit

Permalink
[CollapsingToolbarLayout] Fixed title collapse fade mode color to use…
Browse files Browse the repository at this point in the history
… a Tonal Surface role instead of elevation overlay

Resolves #3525

PiperOrigin-RevId: 564678269
  • Loading branch information
dsn5ft authored and leticiarossi committed Sep 12, 2023
1 parent d16f223 commit 5f2b4b2
Showing 1 changed file with 15 additions and 5 deletions.
Expand Up @@ -61,6 +61,7 @@
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.google.android.material.animation.AnimationUtils;
import com.google.android.material.color.MaterialColors;
import com.google.android.material.elevation.ElevationOverlayProvider;
import com.google.android.material.internal.CollapsingTextHelper;
import com.google.android.material.internal.DescendantOffsetUtils;
Expand Down Expand Up @@ -796,13 +797,22 @@ public void setTitleCollapseMode(@TitleCollapseMode int titleCollapseMode) {
disableLiftOnScrollIfNeeded((AppBarLayout) parent);
}

// If using fade title collapse mode and no content scrim, provide default content scrim based
// on elevation overlay.
// If using fade title collapse mode and no content scrim, provide default content scrim.
if (fadeModeEnabled && contentScrim == null) {
setContentScrimColor(getDefaultContentScrimColorForTitleCollapseFadeMode());
}
}

@ColorInt
private int getDefaultContentScrimColorForTitleCollapseFadeMode() {
ColorStateList colorSurfaceContainer =
MaterialColors.getColorStateListOrNull(getContext(), R.attr.colorSurfaceContainer);
if (colorSurfaceContainer != null) {
return colorSurfaceContainer.getDefaultColor();
} else {
float appBarElevation = getResources().getDimension(R.dimen.design_appbar_elevation);
int scrimColor =
elevationOverlayProvider.compositeOverlayWithThemeSurfaceColorIfNeeded(appBarElevation);
setContentScrimColor(scrimColor);
return elevationOverlayProvider.compositeOverlayWithThemeSurfaceColorIfNeeded(
appBarElevation);
}
}

Expand Down

0 comments on commit 5f2b4b2

Please sign in to comment.