Issue
I have noticed that when I use R.color.myColor, I get a wrong color. But, at the same time, using getColor(R.color.myColor) gives the correct color. For example, I have a #3971e3 color in my app, it gives a purple color when using R.color.myColor but perfectly fine when using getColor(R.color.myColor) or Color.parseColor("#3971e3");.
Why is this so?
Thanks in advance
Solution
R.color.myColor isn't the actual color code. It's a resource id that can be used to look up the color code via getColor. The reason for this is that the actual color of the resource can change based on theme, locale, or a dozen other options if you want it to. So if you need the actual color code, call getColor.
Answered By - Gabe Sechan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.