Programmatically changing underline color of EditText

前端 未结 4 1121
既然无缘
既然无缘 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:27

    @degs's answer is correct. But just add one little note: the AppCompatEditText#setSupportBackgroundTintList is now annotated with @RestrictTo(LIBRARY_GROUP) which means:

    Restrict usage to code within the same group of libraries

    Instead use ViewCompat#setBackgroundTintList. So in your example, it should look like this:

    ColorStateList colorStateList = ColorStateList.valueOf(color);
    ViewCompat.setBackgroundTintList(editText, colorStateList);
    

提交回复
热议问题