I have a clickable TextView that I want to give some colors to. But I don\'t know how. Here are the relevant code snippets from my two files that I\'m working with:
Here is a very simple way programmatically:
private void setColorStateList(TextView view) {
int[][] states = new int[][] {
new int[] { android.R.attr.state_pressed}, // pressed
new int[] { android.R.attr.state_focused}, // focused
new int[] { android.R.attr.state_enabled} // enabled
};
int[] colors = new int[] {
getResources().getColor(R.color.blue),
getResources().getColor(R.color.green),
getResources().getColor(R.color.green)
};
ColorStateList list = new ColorStateList(states, colors);
view.setTextColor(list);
view.setClickable(true);
view.setFocusableInTouchMode(true);
}