Skip to content

Instantly share code, notes, and snippets.

@baz8080
Created January 31, 2017 10:16
Show Gist options
  • Save baz8080/86d6023c74ed70d9408ea500b8577376 to your computer and use it in GitHub Desktop.
Save baz8080/86d6023c74ed70d9408ea500b8577376 to your computer and use it in GitHub Desktop.
Creating ColorStateList programatically
int[][] states = new int[][] {
new int[] { android.R.attr.state_enabled },
new int[] { -android.R.attr.state_enabled }
};
int[] coloursLight = new int[] {
Color.argb(255, 255, 255, 255), // White, active, 100% opaque
Color.argb(128, 255, 255, 255) // White, inactive, 50% opaque
};
int[] coloursDark = new int[] {
Color.argb(138, 0, 0, 0), // Black, active, 54% opaque
Color.argb(66, 0, 0, 0) // Black, inactive, 26% opaque
};
ColorStateList lightColourStateList = new ColorStateList(states, coloursLight);
ColorStateList darkColourStateList = new ColorStateList(states, coloursDark);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment