setTextColor equivalent for TextInputLayout

103 Views Asked by At

I am creating a text inout box using TextInput Layout. I want to apply drawable and colour resources based on different variants of the input box. I have created different xml resource files under res/color and res/drawable directories.

public enum InputTextVariant {
    Standard, Stepper, MultiLine;
}
 public void setVariant(int variantParam) {
        Drawable d;
        ColorStateList csl;
        InputTextVariant variant = SpectrumInputTextVariant.values()[variantParam];
        switch (variant) {
            case Standard:
                csl = AppCompatResources.getColorStateList(getContext(), R.color.textcolor_btn_cta);
                d = AppCompatResources.getDrawable(getContext(), R.drawable.btn_cta_material);
                //setTextColor(csl);
                setBackgroundTintList(csl);
                setBackground(d);

I want to use something similar to setTextColor for a button. I have specified different color and shapes for different states(disabled,hovered,focused etc). How can I load the color resources for this TextInputLayout. I have tried to setBackgroundTint which requires API version >=21. but I need to support for lower versions as well.

1

There are 1 best solutions below

0
On

You can manage tint at drawable level:

Drawable d = AppCompatResources.getDrawable(...);
ColorStateList csl = AppCompatResources.getColorStateList(...);
d = DrawableCompat.wrap(d);
DrawableCompat.setTintList(csl);
setBackground(d);