diff --git a/lib/java/com/google/android/material/internal/CollapsingTextHelper.java b/lib/java/com/google/android/material/internal/CollapsingTextHelper.java index 7a677943cb7..3d551381fab 100644 --- a/lib/java/com/google/android/material/internal/CollapsingTextHelper.java +++ b/lib/java/com/google/android/material/internal/CollapsingTextHelper.java @@ -523,16 +523,20 @@ public void maybeUpdateFontWeightAdjustment(@NonNull Configuration configuration } private boolean shouldUseBoldTypefaces() { - return VERSION.SDK_INT >= VERSION_CODES.S && fontWeightAdjustment >= FontStyle.FONT_WEIGHT_MIN; + return VERSION.SDK_INT >= VERSION_CODES.S + && fontWeightAdjustment != Configuration.FONT_WEIGHT_ADJUSTMENT_UNDEFINED + && fontWeightAdjustment != 0; } @Nullable private Typeface maybeCloneWithAdjustment(@NonNull Typeface typeface) { if (shouldUseBoldTypefaces()) { - return Typeface.create( - typeface, - typeface.getWeight() + fontWeightAdjustment, - typeface.isItalic()); + int adjustedWeight = + MathUtils.clamp( + typeface.getWeight() + fontWeightAdjustment, + FontStyle.FONT_WEIGHT_MIN, + FontStyle.FONT_WEIGHT_MAX); + return Typeface.create(typeface, adjustedWeight, typeface.isItalic()); } return null; }