0

Does anyone know of a way to modify the visual style of how the WebView displays auto-linked text (phone numbers, addresses, etc.)? Or more specifically, can I make the links that WebView detects look like standard clickable hyperlinks? For example,

webView.loadData("My phone number is 3035555555", "text/html", "utf-8"); 

This loads the text into the WebView and it is clickable, but it just looks like the rest of the body text. I also tried putting the text into an HTML file in assets and doing

webView.loadUrl("file:///android_asset/Test.html"); 

But that yielded the same result. Is there something in WebSettings or WebViewClient that controls this behavior I'm missing?

Cheers.

1
  • It seems this is also the default behavior in the Browser application, making it seem that this was the intended effect. I have filed a bug on this issue, feel free to star it! code.google.com/p/android/issues/detail?id=14412 Commented Apr 5, 2011 at 12:25

2 Answers 2

1

You could do this to get what your looking for.

 String header = "< ?xml version=\"1.0\" encoding=\"UTF-8\" ?>"; String data = "< html>< body>< a href='tel:555-5599'>508-776-5510
" "< /body>< /html>";

mWebView.loadData(header+data, "text/html", "UTF-8");

Sign up to request clarification or add additional context in comments.

1 Comment

You're right, we can (and do) pre-link any text we're aware of, but this isn't always possible with dynamic content and really defeats the purpose of auto link detection. Hopefully, Google will address this with some more customization someday.
0

Try this.....

String header = "< ?xml version=\"1.0\" encoding=\"UTF-8\" ?>"; String data = "< html>< body>< a href='tel:555-5599'>508-776-5510 " "< /body>< /html>"; mWebView.loadData(header+data, "text/html", "UTF-8"); 

If you are loading a string of html texts into webView. Then you can use

mWebView.loadData(header+data, "text/html", "UTF-8");

If you have a html file. Then you can use

webView.loadUrl("file:///android_asset/mypage.html"):

Note: Dont forget to put your html file in your assets folder.

Cheers!!! :D

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.