Lorem ipsum dolor si...">

Android webview for loading HTML from strings.xml

So, I have this in Strings.xml:

<string name="sixpackInfo"> <html><body><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. </p> <p><b>Sed dignissim lacinia nunc. Curabitur tortor.</b> Pellentesque nibh. Aenean quam. In sce </body></html> </string> 

I am trying to download and parse this line in webview.

So:

 wvInformation = (WebView) findViewById(R.id.wvInformation); String text = getResources().getString(R.string.sixpackInfo); System.out.println(text); wvInformation.loadData(text, "text/html", null); 

I get the text lorem ipsum in webview, but p tags and b tags take care. text is simply displayed as plain text with markup.

+4
source share
3 answers
 <string name="sixpackInfo"> <![CDATA[<html><body><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. </p> <p><b>Sed dignissim lacinia nunc. Curabitur tortor.</b> Pellentesque nibh. Aenean quam. In sce </body></html> ]]> </string> 
+5
source

It looks like your HTML fragment is not readable as HTML - check what is actually being read (upload it to a file) and see, for example, if there is something before.

0
source

Try it -

wvInformation.loadData(Html.fromHtml(text, "text/html", null);

-one
source

Source: https://habr.com/ru/post/1396580/


All Articles