开发者

Android WebView: Change Auto-Link Display

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.


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");


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜