How do I create ColorStateList programmatically?
Solution 1:
See http://developer.android.com/reference/android/R.attr.html#state_above_anchor for a list of available states.
If you want to set colors for disabled, unfocused, unchecked states etc. just negate the states:
int[][] states = new int[][] {
new int[] { android.R.attr.state_enabled}, // enabled
new int[] {-android.R.attr.state_enabled}, // disabled
new int[] {-android.R.attr.state_checked}, // unchecked
new int[] { android.R.attr.state_pressed} // pressed
};
int[] colors = new int[] {
Color.BLACK,
Color.RED,
Color.GREEN,
Color.BLUE
};
ColorStateList myList = new ColorStateList(states, colors);
Solution 2:
Sometimes this will be enough:
int colorInt = getResources().getColor(R.color.ColorVerificaLunes);
ColorStateList csl = ColorStateList.valueOf(colorInt);