Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set the color of a string directly in string.xml?

I mean something like:

<string name="error" color="#9a1d1d">Error!</string>
like image 299
Gimmy88 Avatar asked Apr 14 '13 08:04

Gimmy88


People also ask

How do I change text color in XML?

Android TextView – Text Color. TextView Text Color – To change the color of text in TextView, you can set the color in layout XML file using textColor attribute or change the color dynamically in Kotlin file using setTextColor() method.


1 Answers

As suggested by rekire not possible to set color the way you are doing.

You can use the method as suggested by rekire.

In you xml you can specify color for your textview as

  android:textColor="#0EFFFF"

You can also set text color programaticaly

  TextView tv= (TextView)findviewById(R.id.textView1);
  tv.setTextColor(Color.RED);  

To set color of particular words in textview, you can use spannable string

    TextView tv= (TextView)findviewById(R.id.textView1);
    tv.setText("");  
    String s="Hello World";
    SpannableString ss=  new SpannableString(s);                
    ss.setSpan(new ForegroundColorSpan(Color.GREEN), 0, 5, 0);  
    tv.setText(ss);
like image 165
Raghunandan Avatar answered Oct 23 '22 02:10

Raghunandan