java - How to append/insert to TextView with retained format -


i have code this:

strings.xml

<string name="message1">your money: <b>1000</b> <b>2000</b></string> <string name="message2">your money: <b>%1$s</b> <b>%2$s</b></string> 

and want show in textview

mainactivity.java

// 1 render 1000 , 2000 in bold correctly textview mtext1 = (textview) findviewbyid(r.id.message1); mtext1.settext(gettext(r.string.message1));  // 1 fail render 1000 , 2000 in bold     int val1 = 1000, val2 = 2000; textview mtext2 = (textview) findviewbyid(r.id.message2); mtext1.settext(string.format(gettext(r.string.message2).tostring(), val1, val2)); 

i want make can format text in bold/italic applying string.format android string resource.

you need take @ android string resource guide. section on styling html markup shows how this.

first need give string resource follows(html escape opening html tags)

<string name="message2">your money: &lt;b>%1$s&lt;/b> &lt;b>%2$s&lt;/b></string> 

then retrieve , format string follows

string text = getstring(r.string.message2, val1, val2); charsequence styledtext = html.fromhtml(text); mtext2.settext(styledtext); 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -