I am trying to change the tinting color of an EditText
View programmatically during runtime. Basically i want to change what you would usually apply as ?attr/colorControlNormal
like in the default background drawable.
Changing the background tint does not correctly apply by just setting a new ColorsStateList
with one color:
editText.setBackgroundTintList( ColorStateList.valueOf( color ) );
For one the result is applied to all EditText
although the tint list is applied and internally mutates the drawable. Also the alpha as specified in the default background 1 is visible at the beginning.
Here is the outcome of setting the tint color on just the first EditText
:
So my question would be: How can I properly apply the tint programmatically to an EditText
?
You must create a custom EditText with a listener to change its own color. After that, when you want to change the color, you just have to call the listener and every single EditText will response this listener.
imageView. drawable. setTintList(null) to clear the tint. Docs: Color state list to use for tinting this drawable, or null to clear the tint This value may be null.
Tint color means when we want to change the color of the image while rendering in ImageView. In XML is very easy to change tint color by just setting up the attribute android:tint="" in the ImageView tag, as shown in the following example.
This works for me:
editText.getBackground().setColorFilter(getResources().getColor(R.color.your_color), PorterDuff.Mode.SRC_ATOP);
Source: Changing EditText bottom line color with appcompat v7
With the newly introduced android.support.v4.graphics.drawable.DrawableCompat#setTint
setting the color is now possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With