Add HTML elements to a string resource file, use string resources directly, and the HTML element has no effect on the workaround

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.