I need to change text color when state change(pressed, focus)…
How to set the text color of a TextView
using ColorsStateList
?
edit, solved:
textView.setTextColor(new ColorStateList(
new int [] [] {
new int [] {android.R.attr.state_pressed},
new int [] {android.R.attr.state_focused},
new int [] {}
},
new int [] {
Color.rgb (255, 128, 192),
Color.rgb (100, 200, 192),
Color.White
}
));
solution 2
textView.setTextColor(getResources().getColorStateList(R.color.your_colors))
Best Solution
If you need to set the colors in code (using ColorStateList), but still want to keep the color states in an XML, you might want to use this:
res/color/your_colors.xml