mirror of
https://github.com/material-components/material-components-android.git
synced 2026-02-20 08:39:55 +08:00
Merge "Fix TextInputLayout not clearing the error on Lollipop" into mnc-ub-dev am: 8bab339
am: ac23e76 * commit 'ac23e764c991f2e72cd1b4c54a7ffa72024e94d7': Fix TextInputLayout not clearing the error on Lollipop Change-Id: I676fdb29773258ba84a0cb6a9cdd6fe029d2ec2f GitOrigin-RevId=d374743e9db623153997cf59efc9658c678d08bf PiperOrigin-RevId: 140560912
This commit is contained in:
parent
451a0f4239
commit
5116a4da25
@ -25,6 +25,7 @@ import android.graphics.PorterDuff;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.DrawableContainer;
|
||||
import android.graphics.drawable.InsetDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
@ -33,6 +34,7 @@ import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StyleRes;
|
||||
import android.support.design.R;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.graphics.drawable.DrawableWrapper;
|
||||
import android.support.v4.view.AccessibilityDelegateCompat;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
@ -721,11 +723,36 @@ public class TextInputLayout extends LinearLayout {
|
||||
} else {
|
||||
// Else reset the color filter and refresh the drawable state so that the
|
||||
// normal tint is used
|
||||
editTextBackground.clearColorFilter();
|
||||
clearColorFilter(editTextBackground);
|
||||
mEditText.refreshDrawableState();
|
||||
}
|
||||
}
|
||||
|
||||
private static void clearColorFilter(@NonNull Drawable drawable) {
|
||||
drawable.clearColorFilter();
|
||||
|
||||
if (Build.VERSION.SDK_INT == 21 || Build.VERSION.SDK_INT == 22) {
|
||||
// API 21 + 22 have an issue where clearing a color filter on a DrawableContainer
|
||||
// will not propagate to all of its children. To workaround this we unwrap the drawable
|
||||
// to find any DrawableContainers, and then unwrap those to clear the filter on its
|
||||
// children manually
|
||||
if (drawable instanceof InsetDrawable) {
|
||||
clearColorFilter(((InsetDrawable) drawable).getDrawable());
|
||||
} else if (drawable instanceof DrawableWrapper) {
|
||||
clearColorFilter(((DrawableWrapper) drawable).getWrappedDrawable());
|
||||
} else if (drawable instanceof DrawableContainer) {
|
||||
final DrawableContainer container = (DrawableContainer) drawable;
|
||||
final DrawableContainer.DrawableContainerState state =
|
||||
(DrawableContainer.DrawableContainerState) container.getConstantState();
|
||||
if (state != null) {
|
||||
for (int i = 0, count = state.getChildCount(); i < count; i++) {
|
||||
clearColorFilter(state.getChild(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureBackgroundDrawableStateWorkaround() {
|
||||
final int sdk = Build.VERSION.SDK_INT;
|
||||
if (sdk != 21 && sdk != 22) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user