In the string.xml file i use the following tag
\"#0000ff\"
If I use
textview
try set color like this may helps you
txt.setTextColor(Color.rgb(0, 87, 48));
this is different way but it can change color , here need Red,Green,Blue Code to pass
You can use
textView1.setTextColor(getResources().getColor(R.color.mycolor))
or
textview1.setBackgroundColor(Color.parseColor("#ffffff"));
or
textview1.setBackgroundColor(Color.RED);
or
textView1.setBackgroundColor(R.color.black);
you should use R.color.CodeColor
. you are using R.string.CodeColor
.
I am basically just merging all the partially good answers.
You defined your color as a String
, but AFAIK Android processes colors as Itegers
.
So use the Colors.xml
file (instead of strings.xml
):
and refer to it in code as R.color.CodeColor
.
(Moreover, I think, there is some naming convention that tells you to name these values all lowercase: code_color
or codecolor
)
Or you can define them as strings, but then you are need to make it an Integer: Color.parseColor(R.string.code_color)
.
Define colors in colors.xml file like that:
<resources>
<color name="CodeColor" >#0000ff</color>
</resources>
Then use color whatever you like in your code using: R.color.CodeColor
Good luck!
I tried something like:
textView.setTextColor(R.color.Red);