Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android - HTML in String resource

I'm trying to justify text by using a WebView and formatting a String resource with HTML as saw in some example:

     <string name="dTxt">
    <html>
        <head></head>
        <bodystyle text-align:justify=""><body> Lorem ipsum dolor sit amet, consectetur  adipiscing elit. 
   Nunc pellentesque, urna nec hendrerit pellentesque, risus massa </body>
   </bodystyle>
   </html>
   </string>

ADT refuses to parse the Strings document with following error:

  W/ResourceType( 2612): Bad XML block: header size 296 or total size 6144712 is larger than data size 0

What is wrong here?

like image 736
Droidman Avatar asked Dec 15 '22 07:12

Droidman


2 Answers

njzk2 is right, < and > are forbidden to use them directly as string. However, you can wrap the HTML in CDATA:

<string name="dTxt">
<![CDATA[
    <html>
        <head></head>
        <bodystyle text-align:justify="">
            <body> Lorem ipsum dolor sit amet, consectetur  adipiscing elit. 
                Nunc pellentesque, urna nec hendrerit pellentesque, risus massa 
            </body>
        </bodystyle>
   </html>
]]>
</string>
like image 149
Marqs Avatar answered Dec 28 '22 08:12

Marqs


try these string Resource with Html.fromHtml(source) inside your java code

like image 31
Tarsem Singh Avatar answered Dec 28 '22 07:12

Tarsem Singh