在 strings.xml 中使用 HTML 標籤,顏色屬性需用十六進制:
<string name="colored_text"><![CDATA[<font color="#FF0000">紅色文字</font>]]></string>
TextView tv = findViewById(R.id.tv);
tv.setText(Html.fromHtml(getString(R.string.colored_text)));
font 標籤的 color 不支持 @color/xxx 資源引用,必須寫死 #RRGGBB 或 #AARRGGBB。HtmlCompat.fromHtml。SpannableString 代碼構建。