Using colors from color.xml in java code

Is there a way to call colors from colors.xml in java? I created an editor and I want to use the colors that I already defined in colors.xml from java how can I do this?

+6
source share
3 answers

To get the 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); 
+5
source

Use this:

  getResources().getColor(R.color.your_color); 
+2
source

You can directly set the text in the text box:

myTextView.setTextColor (GetResources () GetColor (R.color.your_color).);

0
source

Source: https://habr.com/ru/post/986723/


All Articles