Colors can be defined as resources files in Android. Simply create a xml file in the res/values directory called as colors.xml For each color define a color tag with the name attribute equal to color name and contents of the tag set to RGB color defined in hexadecimal notation as shown below:
<?xml version=”1.0″ encoding=”utf-8″?> <resources> <color name=”White”>#FFF</color> <color name=”Black”>#000</color> <color name=”Grey”>#7F7F7F</color> <color name=”DarkGrey”>#4F4F4F</color> <color name=”Green”>#0F0</color> <color name=”TransparentGrey”>#7F000000</color> </resources>
You can define what ever colors you want as resources as it is shown above. Once defined, the Android compiler will automatically create resources identifiers in the R file that you can refer in your code as show below:
public static final class color { public static final int Black=0x7f060001; public static final int DarkGrey=0x7f060003; public static final int Green=0x7f060004; public static final int Grey=0x7f060002; public static final int TransparentGrey=0x7f060005; public static final int White=0x7f060000; }