In this article, we will learn about How to assign Background to a View with Transparency in Android.
Android uses hexadecimal ARGB values in the format.
This first pair of letters, AA, stands for the alpha channel. You need to convert your decimal opacity values to hexadecimal values.
Following is the black color with 50% transparency.
Alpha Hex value process
Take your opacity as the decimal value and multiply it by 255. So if you have a block with 50% opacity, the decimal value would be 0.5. For example: 0.5 x 255 = 127.5
The fraction is not converted to hexadecimal, so you will need to round your number to the nearest whole number. For example, 127.5 turns to 128, 55.25 rounds to 55.
Enter your decimal value in decimal to hex converter like http://www.binaryhexconverter.com/decimal-to-hex-converter and convert your values.
If you return only one value, precede it with a zero. For example, if you’re trying to get 5% opacity and following this process, add a zero before getting the hex value of D so that it shows up as 0D.
How to find the alpha channel value. I have taken the liberty of compiling you with a list of values.
Hex Opacity Values
That’s all about how to assign Background to a View with Transparency in Android.