I need to change the color of the EditText line programmatically, how do I?
I tried to set an xml in the drawable folder, but it does not change the line color anyway ...
I need to change the color of the EditText line programmatically, how do I?
I tried to set an xml in the drawable folder, but it does not change the line color anyway ...
From the appcompat-v7 version and assign it to EditText via the android:theme
attribute.
In the file res/style.xml
declare a new style :
<style name="MyEditTextTheme">
<item name="colorControlNormal">#ff0000</item>
<item name="colorControlActivated">#00ff00</item>
<item name="colorControlHighlight">@color/accent_material_light</item>
</style>
Notes:
@color/accent_material_dark
AppCompatActivity
Add the android:theme
attribute to the EditText declaration:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
.....
.....
android:theme="@style/MyEditTextTheme"/>
Adapted from here
You can not change the color of the line. You can change the background of EditText and you can put a transparent% color with a colored line underneath, like this for example:
Togeneratethese%color%onlineyoucanusethissite Android Holo Generator .
However, I recommend downloading the MaterialEditText library that implements EditTexts with Material Design and has the ability to programmatically change the color of the line