8-digit hexadecimal color problem - Android

4

I'm working on an application where I'm trying to follow the Google Material design guide. On this page, it is recommended to use black color (% color) with 87% opacity as the color of the main texts.

Using a hexadecimal to decimal converter, I reached the value of 57 in the hex base. Joining the desired opacity with the color, I arrived that the final color should be #000000 , but the result was this:

Whileitshouldlooklikethis:

My question is: was there a miscalculation on my part? Is not this how the opacity should be calculated? Does the opacity value vary from 0-100 or 0-255?

My xml color file is this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- cores do android L -->
    <color name="texto">#57000000</color>
    <color name="texto_secundario">#36000000</color>
    <color name="dica">#1A000000</color>
    <color name="divisores">#0C000000</color>

    <color name="laranja">#ffab40</color>
    <color name="laranja_escuro">#ff9100</color>
    <color name="laranja_claro">#ffd180</color>

    <color name="roxo">#673ab7</color>
    <color name="roxo_escuro">#512da8</color>
    <color name="roxo_claro">#d1c4e9</color>
</resources> 
    
asked by anonymous 20.08.2014 / 08:30

1 answer

4

Both colors and opacities in the "web format" are usually interpreted from 00 to ff , that is, from 0 to 255 in decimal.

Multiplying 0xFF (255) by 0.87 gives a value close to 0xDD (221), so black in the desired transparency would be:

   #dd000000

Here's a basic table as a reference:

     0% 0x00          0 
     5% 0x0D         13 
    10% 0x1A         26 
    15% 0x26         38 
    20% 0x33         51 
    25% 0x40         64 
    30% 0x4D         77 
    35% 0x59         89 
    40% 0x66        102 
    45% 0x73        115 
    50% 0x80        128 
    55% 0x8C        140 
    60% 0x99        153 
    65% 0xA6        166 
    70% 0xB3        179 
    75% 0xBF        191 
    80% 0xCC        204 
    85% 0xD9        217 
    90% 0xE6        230 
    95% 0xF2        242 
   100% 0xFF        255 

And here, the desired values in the statement:

    12% 0x1e         30
    26% 0x42         66
    54% 0x89        137 
    87% 0xDD        221
    
20.08.2014 / 08:54