strings.xml
<string name="hoge"><![CDATA[<font color=#f50057><b>Hoge!</b></font>But<br><font color=#304ffe><b>ふBut!</b></font>It is now possible]]></string>
HtmlCompat
public class HtmlCompat {
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static Spanned fromHtml(String source) {
if (VersionUtil.isNougatOrLater()) {
return Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY);
} else {
return Html.fromHtml(source);
}
}
}
activity
text.setText(
HtmlCompat.fromHtml(activity.getString(R.string.hoge))
);
Recommended Posts