AndroidDev AndroidDev - 4 months ago 43x
Android Question

Percent color in Android for Material Design

In Google's spec for material design, I see colors specified as percentages:

To convey a hierarchy of information, you can use different shades for
text. The standard alpha value for text on a white background is 87%
(#000000). Secondary text, which is lower in the visual hierarchy,
should have an alpha value of 54% (#000000).

I don't understand how these percentages work. For example, if the background color is white, what is the color of the text?

What if my background were say #607D8B. What would my text color be? Is it just the background color with the opacity (alpha) set to the percentage?


The percentage are for visibility of the color

When we specify any color using hex format :

First 2 digit : visibility

After 6 digit : RRGGBB

So, the calculation example is :

(87)% of (100) decimel = 87 %   ->    convert to (87)% of (256) in hex 222.72 rounding to 223 which is (DF) in hex

So your color code = #DF607D8B -- primary

Same way, any perentage should be converted to hex

You can check table : here