Programmatically changing underline color of EditText

前端 未结 4 1116
既然无缘
既然无缘 2021-01-04 09:56

I have an ordinary EditText field that I would like to programmatically change the underline color for.



        
4条回答
  •  旧巷少年郎
    2021-01-04 10:51

    You need to set the backgroundTintList (or supportBackgroundTintList) on the EditText to an instance of ColorStateList containing only the color you wish to change the tint to. An easy way to do this in a backwards-compatible way looks like this:

    ColorStateList colorStateList = ColorStateList.valueOf(color);
    editText.setSupportBackgroundTintList(colorStateList);
    

    This will give the EditText the desired underline color.

提交回复
热议问题