How to convert Color.RED code into integer values of color in Android Java?
10,542
Solution 1
Try this:
Color.parseColor("#FF0000")
int color = 0xFFFF0000;
Hope this may help you!
Solution 2
I'd more preffer to use XML file. Suggested solution by Kruba Patel will in fact force developer to remember HEX of color and also redundante of code.
Here XML resource example just call R.color.color_name
please note that R.color.color_name will return generated int value :)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color
name="color_name"
>hex_color</color>
</resources>
Comments
-
Sri almost 2 years
In my android projects i set color for PieChart like this
public static int[] COLORS = new int[] { Color.GREEN, Color.BLUE };
In that import android.graphics.Color; have only few colors around 10. I need more color so i tried to set as integer but didn't working.
Color.alpha(16777184)
for light yello color. this code is not working ? how to set here as integer value of color...?