是否有可能直接在string.xml设置字符串的颜色? [英] Is it possible to set the color of a string directly in string.xml?

查看:211
本文介绍了是否有可能直接在string.xml设置字符串的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思是这样的:

 <字符串名称=错误色=#9a1d1d>错误!< /串>
 

解决方案

所建议的rekire不能设置颜色,你正在做的方式。

您可以使用的方法所建议的rekire。

在你XML中可以指定的颜色为你的TextView作为

 安卓文字颜色=#0EFFFF
 

您还可以设置文字的颜色programaticaly

  TextView的电视=(TextView中)findviewById(R.id.textView1);
  tv.setTextColor(Color.RED);
 

要设置的特定词的颜色在TextView中,你可以使用spannable字符串

  TextView的电视=(TextView中)findviewById(R.id.textView1);
    tv.setText();
    字符串s =Hello World的;
    SpannableString SS =新SpannableString(S);
    ss.setSpan(新ForegroundColorSpan(Color.GREEN),0,5,0);
    tv.setText(SS);
 

I mean something like:

<string name="error" color="#9a1d1d">Error!</string>

解决方案

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);

这篇关于是否有可能直接在string.xml设置字符串的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆