Tima Tima - 6 months ago 17
Android Question

Android get color as string value

If i defined a color in resources

<resources>
<color name="someColor">#123456</color>
</resources>


it's possible to set color by its id, like

view.setTextColor(R.color.someColor);


Is it also possible to get color string value from colors.xml?

Something like

colorStr = getColor(R.color.someColor);
// -> colorStr = "#123456"


If yes, can anybody give an example?

Thank you

Answer

This is your answer

colorStr=getResources().getString(R.color.someColor);

you will get

 colorStr = "#123456"
Comments