I have an ordinary EditText
field that I would like to programmatically change the underline color for.
<EditText
android:id="@+id/edit_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"/>
Other answers suggest changing the background color filter like so:
editText.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_IN);
However, I don't see any change when I run the app. Changing the background itself:
editText.setBackground(color)
changes the entire EditText
to color
- not what I want!
How do I programmatically change the underline color for an EditText
, AppCompatEditText
or TextInputEditText
? I am using version 25.0.1 of the Support Library.
You can apply a custom style to change the colors. To change the hint color you have to use these attributes: hintTextColor and android:textColorHint . To change the bottom line color you have to use the attribute: boxStrokeColor .
How can I remove underline from text in Android? Just add android:background="@null" this line of code into your EditText xml.
@degs's answer is correct. But just add one little note: the AppCompatEditText#setSupportBackgroundTintList
is now annotated with @RestrictTo(LIBRARY_GROUP)
which means:
Restrict usage to code within the same group of libraries
Instead use ViewCompat#setBackgroundTintList
. So in your example, it should look like this:
ColorStateList colorStateList = ColorStateList.valueOf(color);
ViewCompat.setBackgroundTintList(editText, colorStateList);
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