After some existencial questions on how the gray level colors should be defined in our android projects, I’ve decided to check the predefined colors on the android platform:
$ find . -type f -name "colors.xml" -print0 | xargs -0 grep grey
$ find . -type f -name "colors.xml" -print0 | xargs -0 grep gray
./platforms/android-4/data/res/values/colors.xml: <color name="lighter_gray">#ddd</color>
./platforms/android-4/data/res/values/colors.xml: <color name="darker_gray">#aaa</color>
[…]
./platforms/android-10/data/res/values/colors.xml: <color name="lighter_gray">#ddd</color>
./platforms/android-10/data/res/values/colors.xml: <color name="darker_gray">#aaa</color>
[…]
Ok, the first conclusion is that the android platform definetely used a US convention… No surprises there. Two gray level colors are defined in platforms. Now, I should check on the android developers website: here and there and search for gray level colors. According to this documentation, only darker_gray
seems to be public, although lighter_gray
is defined within data/res/values/colors.xml
…
Ok, make a sample stupid project:
$ android create project --name Grayish \
--target android-10 --path /foo/bar/Grayish \
--package org.summo.grayish --activity MyLifeInGray
Let’s define some colors in the project res/values/colors.xml
file:
1 2 3 4 5 6 |
|
Use them (res/layout/main.xml
file):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
Compile and install the project on your device:
$ ant install
A ddms screenshot and a cropping later:
That’s weird but lighter_gray
is not public… We have access to only one gray system color! To conclude: although we could use the system colors, and since one and only one color is just useless, we would rather define lighter_gray
and darker_gray
in our own res/values/colors.xml
file and if we need more grayish colors, we would use a gray_xx
, xx
corresponding to the percentage of white color.
Et voilà !