I'm using the new TextInputLayout to wrap an EditText. When I determine a field has an error I do the following:
Drawable drawable = DrawableCompat.wrap(getEditText().getBackground());
DrawableCompat.setTintList(drawable, ColorStateList.valueOf(Color.RED));
This works on 5.0 and turns the underline red, but does nothing on 4.4 or 4.1 test devices. What am I missing here? Seems so simple and according to google "just works"... pretty sure I have the latest version of it as well:
compile 'com.android.support:design:22.2.0'
FWIW, if I do setColorFilter instead of setTint then it works on all platforms but then I have issues with it going away and not coming back as soon as the focus is set/left/etc... I'd prefer to do it with tint (and really prefer to have the tint apply to the focus and non-focus states if anybody is looking for extra credit lol)
Thanks!
wrap()
wraps theDrawable
into a newDrawableWrapper
. ThisDrawableWrapper
is what is used to implement the tinting on older devices. A consequence of this - sinceDrawableWrapper
is a newDrawable
- is that you have to set theDrawable
returned bywrap()
back to the theEditText
again afterwards. So just calleditText.setBackground(drawable)
and it should work. – AbransetBackgroundDrawable()
before API level 16 andsetBackground()
from API level 16 and upwards. Its best to implement a helper method which checks the current API level and uses the appropriate call. – Abran@Deprecated
is for. How else would you make changes unless for a time supporting both alternatives. Until the majority of all Android devices runs API level 16 or above (which is actually currently at 89% so it basically has already happened) we just have to live with things like this to ensure backwards compatibility. – AbranDrawable
you are using as background for theEditText
. There probably is a separate greenDrawable
specified for the focused state. – AbranDrawable
as background. – Abran