Android 以编程方式将特定颜色设置为ColorStateList

Android 以编程方式将特定颜色设置为ColorStateList,android,textview,textcolor,android-selector,Android,Textview,Textcolor,Android Selector,我根据我的问题创建了StateListDrawable,但是TextView.setTextColor不接受StateListDrawable(奇怪的是它在布局中工作),而是接受ColorStateList。我读了这个 在ColorStateList的构造函数中,它只接受int数组 ColorStateList colorStateList = new ColorStateList( new int[][]{ new int[]{R

我根据我的问题创建了StateListDrawable,但是TextView.setTextColor不接受StateListDrawable(奇怪的是它在布局中工作),而是接受ColorStateList。我读了这个

在ColorStateList的构造函数中,它只接受int数组

ColorStateList colorStateList = new ColorStateList(
            new int[][]{
                    new int[]{R.attr.state_pressed},
                    new int[]{R.attr.state_selected},
                    new int[]{-R.attr.state_selected},
            },
            new int[]{
                    Color.GREEN,
                    Color.BLUE,
                    Color.RED});
颜色没有在colors.xml中定义,因为我下载了这个颜色属性。我怎么能这样定义呢

ColorStateList colorStateList = new ColorStateList(
            new int[][]{
                    new int[]{R.attr.state_pressed}
            },
            **getThisColor**("#e3bb87"));
用这个

ColorStateList colorStateList = new ColorStateList(
            new int[][] { new int[] { R.dimen.padding_large } },
            new int[] {Color.parseColor("#e3bb87")});

您可以使用
ColorStateList
valueOf()
方法返回包含单一颜色的
ColorStateList

ColorStateList.valueOf(Color.parseColor("#e3bb87"))

幸运的是我是第一名D:)这里的dimen.padding\u large有什么意义?