Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How change color of the underline of Edittext on 4.0+?

I have on my app Theme.Holo but I want to change the color of the underline border of edittext.

I don't want a full border around the edittext. I just want to change the color of the edittext layout on version 4.0+ .

How can I do this?

like image 305
silvia_aut Avatar asked Sep 02 '13 11:09

silvia_aut


4 Answers

You could use 9patch. This resource is wonderful example: android holo

like image 176
Peregreen Avatar answered Sep 25 '22 00:09

Peregreen


int color = Color.parse("#HEX")
editText.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
like image 44
SIr Codealot Avatar answered Sep 25 '22 00:09

SIr Codealot


I think you can change android:background to your desired drawable to replace your edit text's default background.

like image 28
user1582281 Avatar answered Sep 23 '22 00:09

user1582281


For those that want a more complete answer. The default color is actually a 9- patch background. So you will need to replace it.

Go to http://android-holo-colors.com/. Here you will see a category called "color".

Click on the colored square beside it and you will see a color swatch come up. Change the color to that desired.

Scroll down and find another category called EditText. Click the yes button beside it.

Finally scroll down to the end of the page and download the generated zip.

Decompress the zip on your computer. You will find a couple of drawable folders according to the different pixel densities. Copy them to the appropriate folders in your project.

There will also be a folder simply called "drawable". In it will be an xml file. If you have a folder called "drawable", different from "drawable-mdpi, drawable-hdpi, etc", copy the xml file to the "drawable" folder, else create one in your "res" folder

Lastly, copy the name of the xml file. Go to the EditText you would like to change and set the xml file as your background. If your xml file was titled edit_text_holo_light, the xml code you would put in your EditText would be:

android:background="@drawable/edit_text_holo_light

Save the project and run.

like image 28
Visionwriter Avatar answered Sep 24 '22 00:09

Visionwriter