I want to give 20% transparency to the background on Android.

Asked 1 years ago, Updated 1 years ago, 117 views

When I make a text view on Android, if there is a background color in the text view, I want to give it about 20% transparency. What should I do?

android android-textview transparency

2022-09-21 15:39

1 Answers

If you want to give 20% transparency, you can put 80% in the alpha value.

<TextView
   ...
   android:background="#CCFF0000" />

For example, if you want to give 20% transparency to red like the code above, you can give #CCFF0000. To explain, you can see CC FF 0000 in two digits after #, each represented by a Hex value, and the preceding CC is an Alpha value, and the higher the value, the more opaque it becomes. And FF is R of RGB and then 0000 is G and B in order.

Each number can be expressed from 0 to 255 (00 to FF), but if 255 is the maximum, if you want to give 20% transparency, you can give 80% of the value. It is 255 * 0.8 = 204, so if you change it to hexadecimal, it will be 0xCC.


2022-09-21 15:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.