简体   繁体   中英

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?

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

int color = Color.parse("#HEX")
editText.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_ATOP);

我认为你可以将android:background更改为你想要的drawable来替换你编辑文本的默认背景。

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.

在EditText xml布局中使用android:backgroundTint=""

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM