Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does R.color.myColor return wrong color and getColor() return correct?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading