How to assign Background to a View with Transparency in Android

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.

#80000000

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

PercentageColor
100%FF
95%F2
90%E6
85%D9
80%CC
75%BF
70%B3
65%A6
60%99
55%8C
50%80
45%73
40%66
35%59
30%4D
25%40
20%33
15%26
10%1A
5%OD
0%00

That’s all about how to assign Background to a View with Transparency in Android.

Next Article

1. How to Iterate Through Java MAP in Android
2. How to Use Java Ternary Conditional Operator in Kotlin
3. How to Create a Static Object in Kotlin Android

Please share this post:
Posts created 64

Ask a Question

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

%d bloggers like this: