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

徘徊边缘 提交于 2019-12-05 09:59:56

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

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

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

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.

use android:backgroundTint="" in your EditText xml layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!