ColorStateList 无法以编程方式工作
ColorStateList doesn't work programmatically
我正在尝试以编程方式
设置我的EditText
的ColorStateList
ColorStateList textColorStateList = new ColorStateList(
new int[][]{
new int[]{android.R.attr.state_enabled},
new int[]{-android.R.attr.state_enabled},
new int[]{},
},
new int[]{
R.color.DARK_GRAY_COLOR,
R.color.LIGHT_RED_COLOR,
R.color.DARK_GRAY_COLOR});
这是我在 EditText
上使用它的方法
editText.setTextColor(textColorStateList);
但是每当我设置 editText.setEnabled(false);
我的 editText
的颜色保持不变。
有什么想法吗?
第二个参数是颜色列表,不是资源id。像
一样使用它
new int[]{
getColor(R.color.DARK_GRAY_COLOR),
getColor(R.color.LIGHT_RED_COLOR),
getColor(R.color.DARK_GRAY_COLOR) }
我正在尝试以编程方式
设置我的EditText
的ColorStateList
ColorStateList textColorStateList = new ColorStateList(
new int[][]{
new int[]{android.R.attr.state_enabled},
new int[]{-android.R.attr.state_enabled},
new int[]{},
},
new int[]{
R.color.DARK_GRAY_COLOR,
R.color.LIGHT_RED_COLOR,
R.color.DARK_GRAY_COLOR});
这是我在 EditText
editText.setTextColor(textColorStateList);
但是每当我设置 editText.setEnabled(false);
我的 editText
的颜色保持不变。
有什么想法吗?
第二个参数是颜色列表,不是资源id。像
一样使用它new int[]{
getColor(R.color.DARK_GRAY_COLOR),
getColor(R.color.LIGHT_RED_COLOR),
getColor(R.color.DARK_GRAY_COLOR) }