color string resource for xml layout

自闭症网瘾萝莉.ら 提交于 2020-01-14 05:32:14

问题


<string name="some_text">this is <font fgcolor="#ffff0000">red</font></string>

or

<string name="some_text">this is <font color="#ffff0000">red</font></string>

is not doing it.

I need to call the string in an xml TextView. How do I get it to work? No I don't want to use a horizontal LinearLayout with a bunch of TextViews.


回答1:


You can't do this. instead of you can set TextView text as HTML like

textview.setText(Html.fromHtml("this is<font color=\"##ffff0000\">red</font>"));

Go to this for more HTML tag support information :html-tags-supported-by-textview




回答2:


TextView doesn't support entering HTML text directly, though some of the other answers seem to show you how to get a Html object from the String. If you want to format the text within a TextView you need to use Spannable instances to format the sections of text to have different colours, fonts etc. This is only good if you don't already have your text in HTML though, of course.



来源:https://stackoverflow.com/questions/22118558/color-string-resource-for-xml-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!