android - How do I create ColorStateList programmatically? -


i trying create colorstatelist programatically using this:

colorstatelist statelist = new colorstatelist(states, colors);  

but not sure 2 parameters.

as per documentation:

public colorstatelist (int[][] states, int[] colors)  

added in api level 1

creates colorstatelist returns specified mapping states colors.

can please explain me how create this?

what meaning of two-dimensional array states?

see http://developer.android.com/reference/android/r.attr.html#state_above_anchor list of available states.

if want set colors disabled, unfocused, unchecked states etc. negate 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); 

Comments