Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get color resource as string

I'm trying to use Color.parseColor() on a color resource:

<color name="redish">#FF0000</color>

I've tried this, but it gives me the error Unknown color:

Color.parseColor(Integer.toHexString(context.getResources().getColor(R.color.redish)))

How do I convert the color resource to a String properly?

like image 357
user5294977 Avatar asked Sep 05 '15 05:09

user5294977


2 Answers

Updated answer:

String colorHex = "#" + Integer.toHexString(ContextCompat.getColor(context, R.color.colorPrimary) & 0x00ffffff);
like image 154
Darush Avatar answered Nov 15 '22 19:11

Darush


I think you missed #

Color.parseColor("#"+Integer.toHexString(ContextCompat.getColor(context, R.color.redish)))
like image 26
N J Avatar answered Nov 15 '22 20:11

N J