Skip to content

Commit 982f74d

Browse files
leticiarossiymarian
authored andcommitted
[TextInputLayout] Fixed cutout padding so text field outline doesn't overlap collapsed hint.
Resolves #2127 PiperOrigin-RevId: 372563674 (cherry picked from commit 87b50c6)
1 parent cee29e9 commit 982f74d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/java/com/google/android/material/textfield/TextInputLayout.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public class TextInputLayout extends LinearLayout {
236236
@NonNull private ShapeAppearanceModel shapeAppearanceModel;
237237

238238
private final int boxLabelCutoutPaddingPx;
239-
private int boxLabelCutoutWidth;
239+
private int boxLabelCutoutHeight;
240240
@BoxBackgroundMode private int boxBackgroundMode;
241241
private int boxCollapsedPaddingTopPx;
242242
private int boxStrokeWidthPx;
@@ -4077,18 +4077,19 @@ private void openCutout() {
40774077
final RectF cutoutBounds = tmpRectF;
40784078
collapsingTextHelper.getCollapsedTextActualBounds(
40794079
cutoutBounds, editText.getWidth(), editText.getGravity());
4080-
boxLabelCutoutWidth = boxStrokeWidthPx;
4081-
cutoutBounds.bottom = cutoutBounds.top + boxLabelCutoutWidth;
40824080
applyCutoutPadding(cutoutBounds);
4083-
// Offset the cutout bounds by the TextInputLayout's left and top paddings to ensure that the
4084-
// cutout is inset relative to the TextInputLayout's bounds.
4085-
cutoutBounds.offset(-getPaddingLeft(), -getPaddingTop());
4081+
boxLabelCutoutHeight = boxStrokeWidthPx;
4082+
cutoutBounds.top = 0;
4083+
cutoutBounds.bottom = boxLabelCutoutHeight;
4084+
// Offset the cutout bounds by the TextInputLayout's left padding to ensure that the cutout is
4085+
// inset relative to the TextInputLayout's bounds.
4086+
cutoutBounds.offset(-getPaddingLeft(), 0);
40864087
((CutoutDrawable) boxBackground).setCutout(cutoutBounds);
40874088
}
40884089

40894090
/** If stroke changed width, cutout bounds need to be recalculated. **/
40904091
private void updateCutout() {
4091-
if (cutoutEnabled() && !hintExpanded && boxLabelCutoutWidth != boxStrokeWidthPx) {
4092+
if (cutoutEnabled() && !hintExpanded && boxLabelCutoutHeight != boxStrokeWidthPx) {
40924093
closeCutout();
40934094
openCutout();
40944095
}

0 commit comments

Comments
 (0)