我从我的问题 Add Color "#e3bb87" to StateListDrawable programmatically 创建了StateListDrawable,但是 TextView.setTextColor 不接受 StateListDrawable(奇怪的是在布局中却可以),而是接受 ColorStateList。我阅读了这个change statelistdrawable text color android button
在 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"));