I am trying to create a ColorStateList
programatically using this:
ColorStateList stateList = new ColorStateList(states, colors);
But I am not sure what are the two parameters.
As per the documentation:
public ColorStateList (int[][] states, int[] colors)
Added in API level 1
Creates a ColorStateList that returns the specified mapping from states to colors.
Can somebody please explain me how to create this?
What is the meaning of two-dimensional array for states?
Sometimes this will be enough:
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:
The first dimension is an array of state sets, the second ist the state set itself. The colors array lists the colors for each matching state set, therefore the length of the colors array has to match the first dimension of the states array (or it will crash when the state is "used"). Here and example:
hope this helps.
EDIT example: a xml color state list like:
would look like this
Unfortunately none of the solutions works for me.
This is constructor from source code:
My builder class for create
ColorStateList
Example Using
if you use the resource the Colors.xml