Bold characters in string.xml are not shown on screen Bold characters in string.xml are not shown on screen android android

Bold characters in string.xml are not shown on screen


So after a day of search, I found the desired answer on Android Developers website! The Link to the page is here: https://developer.android.com/guide/topics/resources/string-resource.html

Sometimes you may want to create a styled text resource that is also used as a format string. Normally, this won't work because the String.format(String, Object...) method will strip all the style information from the string. The work-around to this is to write the HTML tags with escaped entities, which are then recovered with fromHtml(String), after the formatting takes place.

Basicaly, the change that I would make based on my original question is to replace the bracket "<" with the HTML tag for that, which is "&lt" + ";" (Type them together in your xml file! I had to separate them because StackOverflow will diplay the tag as the bracket itself.) For more detailed explanation, please see the Styling with HTML markup section from the website that I posted above.


i've had success using getText instead of getString. It seems to maintain styling.

from the docs:

You can use either getString(int) or getText(int) to retrieve a string. getText(int) retains any rich text styling applied to the string.


You need to format the text using Html.fromHtml or using a SpannableString.

Html.fromHtml example:

textView.setText(Html.fromHtml(getString(R.string.example_string, "good question")));

Edit:

If you're having trouble passing the tags through, its because it needs to be escaped by CDATA.

eg. <string name="example_string">This is a <![CDATA[<b>%1$s</b>]]></string>