Webview does not show hyperlinks

I have a line: myFullString that looks like this:

<html> <body style="background-color: transparent; margin-top:75px; padding:0px;"> <style type="text/css"> p {margin-left:40px; margin-right:40px; margin-top:40px; margin-bottom:40px; } </style> <p> <font face="helvetica" size=8 color=white> <b> Heading </b></font> <font face="helvetica" size=6> <br/> <br/> <br/> Address Line 1 <br/> Address Line 2 <br/> <br/> Tel: PhoneNumber <br/> Fax: Fax No <br/> <br/> <br/><br/> </font></p> </body></html> 

I want the phone numbers and / or links to appear as a click / hello. So I wrote the following code:

  Spannable sp = new SpannableString(myFullString.toString()); Linkify.addLinks(sp, Linkify.ALL); final String html = Html.toHtml(sp) ; mWebView.setClickable(true); mWebView.loadData(html, "text/html", "utf-8"); 

I get the following result: hyperlink exists but it shows the whole file

In this web view, the texts are hyperlinks, but we can see the tags.

I also tried using the following code:

 Spannable sp = new SpannableString(myFullString.toString()); Linkify.addLinks(sp, Linkify.ALL); mWebView.loadDataWithBaseURL(null, sp.toString(),"text/html", "utf-8", "about:blank"); 

But he gives the following conclusion:

loadDataWithBaseURL

It displays the correct text font, but does not bind texts.

How can I change my code so that links are displayed and it will not show tags? Web browsing content is created dynamically.

+4
source share
1 answer

Since I could not find an easier way ...

I did something like this for every line that should appear on the web page:

  String str=mWebFileArray [i].toString(); if(str.contains("<!- ")){ str.replace("<!- ", "<!-- ").replace(" ->", " -->"); }else{ Spannable sp = new SpannableString(str); Linkify.addLinks(sp, Linkify.ALL); str = Html.toHtml(sp) ; } myArray.add(str); 

now it binds a valid text ....

+1
source

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


All Articles