Android 以编程方式设置editText高亮显示颜色

Android 以编程方式设置editText高亮显示颜色,android,colors,android-edittext,underline,Android,Colors,Android Edittext,Underline,我想改变编辑文本行的颜色语法,如果它的重点 我已经尝试过使用colorStateList int[][] states = new int[][]{ new int[]{android.R.attr.state_focused}, new int[]{android.R.attr.state_active }, new int[]{ -android.R.attr.state_enabl

我想改变编辑文本行的颜色语法,如果它的重点

我已经尝试过使用colorStateList

int[][] states = new int[][]{
                new int[]{android.R.attr.state_focused},   
                new int[]{android.R.attr.state_active },    
                new int[]{ -android.R.attr.state_enabled},   
                new int[]{android.R.attr.state_enabled},   
        };

        int[] colors = new int[]{
                highlightColor,
                defaultColor,
                defaultColor,
                defaultColor
        };

        ColorStateList myList = new ColorStateList(states, colors);
        editText.setBackgroundTintList(myList);
我可以更改线条的正常颜色,但焦点始终是应用程序中EditText的默认颜色

有了这个默认值是灰色,聚焦是默认的应用程序让说绿色,但我想让说红色的聚焦


建议线程中的答案是基于XML的,我必须动态设置它,而且只有高亮/聚焦颜色不同,正常颜色保持灰色

创建一个自定义的
EditText
并添加
this.setBackgroundTintList(ColorStateList.valueOf(color))到构造函数中。

可能重复