States are agreed in the order in which they are defined. So, android.R.attr.state_enabledwill be matched before android.R.attr.state_pressed.
Since the button is turned on, the first positive match will be against android.R.attr.state_enabled, and the color ContextCompat.getColor(context, R.color.tint)will be selected. Since a positive match is found, it does not matter if the button is pressed or not.
- android.R.attr.state_pressed android.R.attr.state_enabled. :
- > android.R.attr.state_pressed, → ContextCompat.getColor(context, R.color.primary).
→ android.R.attr.state_pressed , → android.R.attr.state_enabled , → ContextCompat.getColor(context, R.color.tint).
:
int[][] states = new int[][]{
new int[]{android.R.attr.state_pressed},
new int[]{android.R.attr.state_enabled}
};
int[] colors = new int[]{
ContextCompat.getColor(context, R.color.primary),
ContextCompat.getColor(context, R.color.tint)
};
setSupportBackgroundTintList(new ColorStateList(states, colors));