How can I save color values inside array.xml and retrieve its back to my code as Color [] array?
Thanks beforehand!
If this is in array.xml:
- #ffffff
- #000000
This will give you the color values for that array:
TypedArray ta = context.getResources().obtainTypedArray(R.array.colors);
int[] colors = new int[ta.length()];
for (int i = 0; i < ta.length(); i++) {
colors[i] = ta.getColor(i, 0);
}
ta.recycle();
This just expands on the TypedArray example in the docs: http://developer.android.com/guide/topics/resources/more-resources.html#TypedArray
Hope it helps!