Skip to content

Commit

Permalink
[TextInputLayout] Adding setBoxBackgroundColorStateList method and fi…
Browse files Browse the repository at this point in the history
…xing setBoxBackgroundColor method not changing focused and hovered states color like it did originally.

Resolves material-components#1191

PiperOrigin-RevId: 308275897
  • Loading branch information
leticiarossi authored and dsn5ft committed Apr 25, 2020
1 parent 167020a commit e5a85a2
Showing 1 changed file with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@ public interface OnEndIconChangedListener {
private ColorStateList strokeErrorColor;

@ColorInt private int defaultFilledBackgroundColor;
@ColorInt private final int disabledFilledBackgroundColor;
@ColorInt private final int focusedFilledBackgroundColor;
@ColorInt private final int hoveredFilledBackgroundColor;
@ColorInt private int disabledFilledBackgroundColor;
@ColorInt private int focusedFilledBackgroundColor;
@ColorInt private int hoveredFilledBackgroundColor;

@ColorInt private int disabledColor;

Expand Down Expand Up @@ -1089,7 +1089,8 @@ public void setBoxBackgroundColorResource(@ColorRes int boxBackgroundColorId) {
}

/**
* Set the filled box's background color.
* Sets the filled box's default background color. Calling this method will make the background
* color not be stateful, if it was before.
*
* <p>Note: The background color is only supported for filled boxes. When used with box variants
* other than {@link BoxBackgroundMode#BOX_BACKGROUND_FILLED}, the box background color may not
Expand All @@ -1102,12 +1103,38 @@ public void setBoxBackgroundColor(@ColorInt int boxBackgroundColor) {
if (this.boxBackgroundColor != boxBackgroundColor) {
this.boxBackgroundColor = boxBackgroundColor;
defaultFilledBackgroundColor = boxBackgroundColor;
focusedFilledBackgroundColor = boxBackgroundColor;
hoveredFilledBackgroundColor = boxBackgroundColor;
applyBoxAttributes();
}
}

/**
* Returns the filled box's background color.
* Sets the box's background color state list.
*
* <p>Note: The background color is only supported for filled boxes. When used with box variants
* other than {@link BoxBackgroundMode#BOX_BACKGROUND_FILLED}, the box background color may not
* work as intended.
*
* @param boxBackgroundColorStateList the color state list to use for the box's background color
*/
public void setBoxBackgroundColorStateList(@NonNull ColorStateList boxBackgroundColorStateList) {
defaultFilledBackgroundColor = boxBackgroundColorStateList.getDefaultColor();
boxBackgroundColor = defaultFilledBackgroundColor;
disabledFilledBackgroundColor =
boxBackgroundColorStateList.getColorForState(
new int[]{-android.R.attr.state_enabled}, -1);
focusedFilledBackgroundColor =
boxBackgroundColorStateList.getColorForState(
new int[]{android.R.attr.state_focused, android.R.attr.state_enabled}, -1);
hoveredFilledBackgroundColor =
boxBackgroundColorStateList.getColorForState(
new int[]{android.R.attr.state_hovered, android.R.attr.state_enabled}, -1);
applyBoxAttributes();
}

/**
* Returns the filled box's default background color.
*
* @return the color used for the filled box's background
* @see #setBoxBackgroundColor(int)
Expand Down

0 comments on commit e5a85a2

Please sign in to comment.