Issue
I have a Question, I play a lot with opacity while defining colors, but there is a problem in android, U have to define all colors in colors.xml file & I have already defined thier about 145 colors in colors.xml file,
Now the problem is if i write in colors.xml for all types of opacity values for each color, As you know there are 21 opacity types e.g:
Example:
<color name="black">#000000</color>
<color name="a_black">#FF000000</color>
<color name="b_black">#F2000000</color>
<color name="c_black">#D9000000</color>
<color name="d_black">#CC000000</color>......
Hex Opacity Values
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% — 0D
0% — 00
This defining all colors with opacities means 21 * 145 = 3045 colors
and this will take hours to write in colors.xml file and will make the file large.
- Is there any way to have all colors with opacities in 'colors.xml' file without wasting time and without making colors.xml file large?.
- Is there possible that I can write those 145 colors on 'colors.xml' file but change their opacity when using it for any
background propertyor for anytext colorproperty inactivity_ main.xml?, If it is possible then how can we do that?
Thanks In Advance.
Solution
You can do that programmatically. You need to define the base colors in your colors.xml and then control the opacity from your code wherever necessary.
colorWith25Opacity = (R.color.black & 0x00FFFFFF) | 0x40000000;
You might also consider using this library to get the color code of your desired color like this.
String colorCode = ColorTransparentUtils.transparentColor10(R.color.a_black);
Check the answers provided here and here.
Answered By - Reaz Murshed
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.