I want to set start icon for my TextInputLayout
programmatically, but I faced problem with his color. When I set drawable, its color becomes gray, but original color of it is orange. I know that I can change its color by using startIconTint
parameter in xml, but I want to change its color programmatically. Can someone help me with this.
Hint color could be set via “android:textColorHint” parameter of TextInputLayout. This parameter also changes the label default color (label focused color could also be changed in other ways). Bottom line color could be changed with “app:backgroundTint” attribute of EditText view. colors.
The primary use of a TextInputLayout is to act as a wrapper for EditText(or its descendant) and enable floating hint animations. Rule of Thumb : TextInputLayout should wrap TextInputEditText instead of the normal EditText.
Just use the methods setStartIconDrawable
and setStartIconTintList
:
textInputLayout.setStartIconDrawable(...);
textInputLayout.setStartIconTintList(ContextCompat.getColorStateList(this,R.color.text_input_selector));
You can use a color or a color selector.
Something like:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?attr/colorPrimary" android:state_activated="true"/>
<item android:alpha="0.38" android:color="?attr/colorOnSurface" android:state_enabled="false"/>
<item android:alpha="0.54" android:color="?attr/colorOnSurface"/>
</selector>
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