Skip to content

Commit 6015a4e

Browse files
leticiarossipekingme
authored andcommitted
[TextInputLayout] Adjusted background of collapsed hint to not overlap with edit text's background.
Resolves #1660 Resolves #1319 PiperOrigin-RevId: 353645196
1 parent 66f9a92 commit 6015a4e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ public class TextInputLayout extends LinearLayout {
231231
@NonNull private ShapeAppearanceModel shapeAppearanceModel;
232232

233233
private final int boxLabelCutoutPaddingPx;
234+
private int boxLabelCutoutWidth;
234235
@BoxBackgroundMode private int boxBackgroundMode;
235236
private int boxCollapsedPaddingTopPx;
236237
private int boxStrokeWidthPx;
@@ -3980,13 +3981,23 @@ private void openCutout() {
39803981
final RectF cutoutBounds = tmpRectF;
39813982
collapsingTextHelper.getCollapsedTextActualBounds(
39823983
cutoutBounds, editText.getWidth(), editText.getGravity());
3984+
boxLabelCutoutWidth = boxStrokeWidthPx;
3985+
cutoutBounds.bottom = cutoutBounds.top + boxLabelCutoutWidth;
39833986
applyCutoutPadding(cutoutBounds);
39843987
// Offset the cutout bounds by the TextInputLayout's left and top paddings to ensure that the
39853988
// cutout is inset relative to the TextInputLayout's bounds.
39863989
cutoutBounds.offset(-getPaddingLeft(), -getPaddingTop());
39873990
((CutoutDrawable) boxBackground).setCutout(cutoutBounds);
39883991
}
39893992

3993+
/** If stroke changed width, cutout bounds need to be recalculated. **/
3994+
private void updateCutout() {
3995+
if (cutoutEnabled() && !hintExpanded && boxLabelCutoutWidth != boxStrokeWidthPx) {
3996+
closeCutout();
3997+
openCutout();
3998+
}
3999+
}
4000+
39904001
private void closeCutout() {
39914002
if (cutoutEnabled()) {
39924003
((CutoutDrawable) boxBackground).removeCutout();
@@ -3995,9 +4006,7 @@ private void closeCutout() {
39954006

39964007
private void applyCutoutPadding(@NonNull RectF cutoutBounds) {
39974008
cutoutBounds.left -= boxLabelCutoutPaddingPx;
3998-
cutoutBounds.top -= boxLabelCutoutPaddingPx;
39994009
cutoutBounds.right += boxLabelCutoutPaddingPx;
4000-
cutoutBounds.bottom += boxLabelCutoutPaddingPx;
40014010
}
40024011

40034012
@VisibleForTesting
@@ -4091,6 +4100,10 @@ void updateTextInputBoxState() {
40914100
boxStrokeWidthPx = boxStrokeWidthDefaultPx;
40924101
}
40934102

4103+
if (boxBackgroundMode == BOX_BACKGROUND_OUTLINE) {
4104+
updateCutout();
4105+
}
4106+
40944107
// Update the text box's background color based on the current state.
40954108
if (boxBackgroundMode == BOX_BACKGROUND_FILLED) {
40964109
if (!isEnabled()) {

0 commit comments

Comments
 (0)