Problem with 8 digit hexadecimal colors - Android

Asked

Viewed 937 times

4

I am working on an app where I am trying to follow Google’s Material design guide. On this page, it is recommended to use the black color (#000000) with 87% opacity as the color of the main texts.

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

Cor dos textos muito clara

While it should look like this:

Cor do texto material

My question is: was there a miscalculation on my part? Isn’t this how opacity should be calculated? The opacity value ranges from 0-100 or 0-255?

My color xml 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> 

1 answer

4


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

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

   #dd000000

Follows a basic table as 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 values desired in the statement:

    12% 0x1e         30
    26% 0x42         66
    54% 0x89        137 
    87% 0xDD        221
  • Thanks for the quick reply! By the visa was just a miscalculation of mine. I didn’t think about the possibility of the interval being 255 values, instead of 100 as I had considered.

  • 1

    @Renanlazarotto added the table of transparency values you mentioned in the statement.

  • Thanks again! I will save this list for future reference.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.