Skip to content

Commit

Permalink
[TextInputLayout] Fix editText paddings on pre-Lollipop
Browse files Browse the repository at this point in the history
Resolves #3583
Resolves #3582

GIT_ORIGIN_REV_ID=356f7488505470656d26b0452dae78ae01475022
PiperOrigin-RevId: 574833205
  • Loading branch information
pubiqq authored and drchen committed Oct 19, 2023
1 parent 17baf71 commit 2590c42
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -846,10 +846,30 @@ void updateEditTextBoxBackgroundIfNeeded() {
|| boxBackgroundMode == BOX_BACKGROUND_NONE) {
return;
}
ViewCompat.setBackground(editText, getEditTextBoxBackground());
updateEditTextBoxBackground();
boxBackgroundApplied = true;
}

private void updateEditTextBoxBackground() {
Drawable editTextBoxBackground = getEditTextBoxBackground();

// On pre-Lollipop, setting a LayerDrawable as a background always replaces the original view
// paddings with its own, so we preserve the original paddings and restore them after setting
// a new background.
if (VERSION.SDK_INT < VERSION_CODES.LOLLIPOP
&& editTextBoxBackground instanceof LayerDrawable) {
int paddingLeft = editText.getPaddingLeft();
int paddingTop = editText.getPaddingTop();
int paddingRight = editText.getPaddingRight();
int paddingBottom = editText.getPaddingBottom();

ViewCompat.setBackground(editText, editTextBoxBackground);
editText.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
} else {
ViewCompat.setBackground(editText, editTextBoxBackground);
}
}

@Nullable
private Drawable getEditTextBoxBackground() {
if (!(editText instanceof AutoCompleteTextView) || isEditable(editText)) {
Expand Down

0 comments on commit 2590c42

Please sign in to comment.