I created StateListDrawable from my question Add Color "#e3bb87" to StateListDrawable programmatically , but TextView.setTextColor does not take StateListDrawable (strange it works in layout) but ColorStateList . I read this change statelistdrawable text color android button
In the constructor of ColorStateList, it only accepts arrays of 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});
The color is not defined in colors.xml because I download this color attribute. How can I define like this ?
ColorStateList colorStateList = new ColorStateList(
new int[][]{
new int[]{R.attr.state_pressed}
},
**getThisColor**("#e3bb87"));
Use this
ColorStateList colorStateList = new ColorStateList(
new int[][] { new int[] { R.dimen.padding_large } },
new int[] {Color.parseColor("#e3bb87")});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With