In Android project's strings.xml file i have following html text
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="myHeadStr"><b><u>bold, underline </u></b></string> ... </resources>
When i read this into getString(R.string.myHeadStr) it gives only text "bold, underline" it forgets the html tags and ....
how to read complete string with html tags from string.xml
A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings: String. XML resource that provides a single string.
text. HTML that processes HTML strings into displayable styled text and then we can set the text in our TextView. We can also use WebView for displaying HTML content. Currently Android does not support all the HTML tags but it supports all major tags.
How can I write character & in the strings. xml? In android studio, you can simply press Alt+Enter and it will convert for you.
Use XML CDATA
<string name="demoStr"><Data><![CDATA[ <b>ABC</b> ]]> </Data></string>
getString() will be got "<b>ABC</b>"
Replace < with <
<string name="myHeadStr"><b><u>bold, underline </u></b></string>
Then, when retrieving:
Html.fromHtml(getResources().getString(R.string.myHeadStr));
This is the prescribed way of doing in android documentation. Read the paragraph titled: "Styling with HTML markup" in this link: http://developer.android.com/guide/topics/resources/string-resource.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With