有什么办法让Android中的WebView自动链接的网址和电话号码? [英] Is there any way to have WebView auto-link URLs and phone numbers in Android?
问题描述
如果一个页面都有一个URL或在其上的电话号码是不是链接有什么办法让的的WebView 识别它,并自动把它变成像你可以用的TextView 链接一> S'
If a page has a URL or a phone number on it that isn't a link is there any way to have WebView recognize it and automatically turn it into a link like you can with TextViews?
随着的TextView
您只需设置安卓自动链接
到所需设置:
With a TextView
you would simply set the android:autoLink
to the desired settings:
<TextView
android:autoLink="web|phone"
... />
但我找不到任何相当的的WebView
。
推荐答案
我不知道任何这将使这项工作只是通过更改设置,而是一个解决方法是等待,直到网页完成加载和然后执行:
I don't know about any way which would make this work just by changing a setting, but a workaround would be to wait until the web page finishes loading and then do:
yourWebView.loadUrl("javascript:(function(){ /* code that creates links */ })()");
这将JavaScript插入到已加载网页。 有可略长的例子在这里: http://lexandera.com/ 2009/01 /注射JavaScript的 - 到 - 一个-的WebView / 。
This will inject javaScript into the already loaded web page. There's a slightly longer example available here: http://lexandera.com/2009/01/injecting-javascript-into-a-webview/.
您可以找到JavaScript源创建的链接,如果你看看Linkify脚本来源的Greasemonkey(它是用于Firefox的插件,以防万一你不熟悉它)。我相信它自带的默认安装。
You can find the JavaScript source for creating links if you take a look at the source of Linkify script for Greasemonkey (it's a plugin for Firefox in case you're not familiar with it). I believe it comes with the default install.
这篇关于有什么办法让Android中的WebView自动链接的网址和电话号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!