Skip to content

Commit 2590c42

Browse files
pubiqqdrchen
authored andcommitted
[TextInputLayout] Fix editText paddings on pre-Lollipop
Resolves #3583 Resolves #3582 GIT_ORIGIN_REV_ID=356f7488505470656d26b0452dae78ae01475022 PiperOrigin-RevId: 574833205
1 parent 17baf71 commit 2590c42

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,10 +846,30 @@ void updateEditTextBoxBackgroundIfNeeded() {
846846
|| boxBackgroundMode == BOX_BACKGROUND_NONE) {
847847
return;
848848
}
849-
ViewCompat.setBackground(editText, getEditTextBoxBackground());
849+
updateEditTextBoxBackground();
850850
boxBackgroundApplied = true;
851851
}
852852

853+
private void updateEditTextBoxBackground() {
854+
Drawable editTextBoxBackground = getEditTextBoxBackground();
855+
856+
// On pre-Lollipop, setting a LayerDrawable as a background always replaces the original view
857+
// paddings with its own, so we preserve the original paddings and restore them after setting
858+
// a new background.
859+
if (VERSION.SDK_INT < VERSION_CODES.LOLLIPOP
860+
&& editTextBoxBackground instanceof LayerDrawable) {
861+
int paddingLeft = editText.getPaddingLeft();
862+
int paddingTop = editText.getPaddingTop();
863+
int paddingRight = editText.getPaddingRight();
864+
int paddingBottom = editText.getPaddingBottom();
865+
866+
ViewCompat.setBackground(editText, editTextBoxBackground);
867+
editText.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
868+
} else {
869+
ViewCompat.setBackground(editText, editTextBoxBackground);
870+
}
871+
}
872+
853873
@Nullable
854874
private Drawable getEditTextBoxBackground() {
855875
if (!(editText instanceof AutoCompleteTextView) || isEditable(editText)) {

0 commit comments

Comments
 (0)