Escape HTML in string resource
I. Description of requirements
Assigning a string resource in the Res repository to TextView, note that this is a string resource, to achieve the following effect
"Phone number not tied?" binding ", the last side of the two words to turn red.
Second, the realization method
The idea is as follows, to bind two words with <font> do processing.
<string > Not tied phone number? <font color= "#0f9afc" > Bindings </font></string>
Third, the problem description
If you do, use the code below to achieve the effect I want.
Textview.settext (html.fromhtml (getString (r.string.test_string)));
Iv. Solutions
Found a solution on Google, connect to share to everyone
<a target=_blank href= "http://www.grokkingandroid.com/android-quick-tip-formatting-text-with-html-fromhtml/" > Click to open the link </a>
The modified code is as follows:
<string name= "Test_string" ><! [Cdata[not tied to mobile phone number?] <font color= "#0f9afc" > Bindings </font>]]></string>
V. Summary
Product needs of all kinds of situations have, can be convenient to do, I am convenient to do, this little knowledge point, hope to help everyone, go home to eat, evening to find a movie to see, I wish everyone a pleasant dinner.
Copyright NOTICE: This article is the original blogger articles, reproduced please indicate the source.
Add HTML elements to a string resource file, use string resources directly, and the HTML element has no effect on the workaround