How can I save color values inside array.xml and retrieve its back to my code as Color [] array?
Thanks beforehand!
Define your color resources, then add them to an array for access.
#FF007F
#FF0000
#FF7F00
#FFFF00
#7FFF00
#00FF00
#00FF7F
#00FFFF
#007FFF
#0000FF
#7F00FF
#FF00FF
- @color/bright_pink
- @color/red
- @color/orange
- @color/yellow
- @color/chartreuse
- @color/green
- @color/spring_green
- @color/cyan
- @color/azure
- @color/blue
- @color/violet
- @color/magenta
Then access them like this:
int[] rainbow = context.getResources().getIntArray(R.array.rainbow);
for (int i = 0; i < tileColumns; i++) {
paint.setColor(rainbow[i]);
// Do something with the paint.
}