答案 0 :(得分:1)
您可以使用Spannable
来达到您的愿望效果。
TextView textView;
String sampleText = "This is <font color='#ff0000'>DISCLAIMER:</font>. Rest of your text or <font color='#00ff00'>Green color</font>.";
// You can use color='red' or color='green'
textView.setText(Html.fromHtml(sampleText), TextView.BufferType.SPANNABLE);
修改强>
在string.xml中定义一个字符串
<string name="sample_text" formatted="false"><![CDATA[
<font color=\"red\">DISCLAIMER:</font>
<font color=\"#000000\">
Rest of your text in black color
</font>.
]]></string>
在您的活动/片段类
中TextView tvSample = /*initialize your text view*/;
String text = getString(R.string.sample_text);
tvSample.setText(Html.fromHtml(text), TextView.BufferType.SPANNABLE);