4

I load some html string to a webview and I want to linkify phone numbers, addresses and emails. But if i use Spannable to pass html content into Linkify.addLinks() method all html layout breaks down.

        String htmlText = "<some_html></some_html>";
        SpannableString spannableString = new SpannableString(Html.fromHtml(htmlText));
        Linkify.addLinks(spannableString, Linkify.ALL);
        htmlText = Html.toHtml(spannableString);

So, how to linkify html content before I load it into webview?

AinisSK
  • 306
  • 1
  • 10

1 Answers1

0

In your TextView's xml layout, you should add the following:

android:autoLink="all"
android:linksClickable="true"

<a href="www.google.com">Google!</a>"
Ratilal Chopda
  • 4,162
  • 4
  • 18
  • 31
  • Sorry but, I know that there is a way to add auto links in `TextView`, you can also use `LinkMovementMethod`, but the question is about `webview` – AinisSK May 17 '17 at 10:09
  • 1
    Remember to escape double quotes! – Zoe May 17 '17 at 10:20