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


in string.xml file, have this:

<string name="example_string"><b>this</b> <b>%1$s</b></string> 

and placed textview:

textview.settext(getstring(r.string.example_string, "good question")); 

the "good question" argument passed getstring() method not shown in bold. word "this" not shown in bold! what's reason , how solve it?

=========================================================================

i know how use html.fromhtml(), method not support inserting string place holder have defined in string resource. if trying tell me html.fromhtml() exists, please not reply...

so after day of search, found desired answer on android developers website! link page here: https://developer.android.com/guide/topics/resources/string-resource.html

sometimes may want create styled text resource used format string. normally, won't work because string.format(string, object...) method strip style information string. work-around write html tags escaped entities, recovered fromhtml(string), after formatting takes place.

basicaly, change make based on original question replace bracket "<" html tag that, "&lt" + ";" (type them in xml file! had separate them because stackoverflow diplay tag bracket itself.) more detailed explanation, please see styling html markup section website posted above.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -