android – How to programmatically change the edittext line color


I need to change the EditText line color programmatically, how do I?

I tried to define an xml in the drawable folder, but it doesn't change the line color anyway…


From version v22.1 of appcompat-v7 it is possible to define a style and assign it to EditText through the android:theme attribute.

In the res/style.xml file 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>


  • Change the colors to your liking.
  • With these settings the line is red when "out focus" and green "in focus"
  • If your theme is dark use @color/accent_material_dark
  • In order for your Activity to work, it will have to inherit from AppCompatActivity

Add the android:theme attribute to the EditText declaration:


adapted from here

Scroll to Top