Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using colors from color.xml in java code [closed]

Is there any way to call colors from colors.xml in java? I have created an editor and i want use those colors which i have already defined in colors.xml from java how can i do this ?

like image 829
Assad Avatar asked May 07 '15 09:05

Assad


2 Answers

To get a color as an int, use the following:

int myColor = getResources().getColor(R.color.myColor);

Then, to use this color in a TextView, use the following:

myTextView.setTextColor(myColor);
like image 161
Gil Moshayof Avatar answered Nov 11 '22 11:11

Gil Moshayof


Use this:

 getResources().getColor(R.color.your_color); 
like image 22
Farhan C K Avatar answered Nov 11 '22 10:11

Farhan C K