I have a long text in one of the strings at strings.xml. I want to make bold and change the color of some words in that text.
How can I do it?
Use html tag inside string resources :-
Your text ]]>
And get bold text from string resources like :-
private Spanned getSpannedText(String text) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return Html.fromHtml(text, Html.FROM_HTML_MODE_COMPACT);
} else {
return Html.fromHtml(text);
}
}
String s = format(context.getResources().getString(R.string.string_resource_name));
textView.setText(getSpannedText(s));