禁用web视图的自动Linkify [英] Disable the automatic Linkify of Webview
问题描述
我有我创建一个web视图。这似乎自动将linkifying数字到电话:网址。我没有看到一个方法来消除这种能力(至少没有类似的方式在一个TextView启用它)。
I have a webview that I am creating. It seems to automatically be linkifying numbers into tel: urls. I didn't see a way to remove this ability (at least nothing similar to the way to enable it on a textview).
在code是pretty的简单:
The code is pretty simple:
// populate the web view
WebView webView = (WebView) findViewById(R.id.app_info_webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
webView.setBackgroundColor(0);
String url = APP_INFO_BODY_HTML + "?versionName=" + versionName;
webView.loadUrl(url);
我在页面底部的版权声明,Android是改变了2011到打开拨号器可点击的链接。此外,应用程序版本1.0.0在拨号程序中打开。
I have a copyright notice at the bottom of the page, android is changing the 2011 into a clickable link that opens the dialer. Also, the App version 1.0.0 opens in the dialer.
有没有一种方法来禁用此功能?
Is there a way to disable this functionality?
更新:我刚刚发现,这似乎依赖于设备......发生在对Droid X,而不是三星的Captivate,不能在Nexus S,而不是模拟器
Update: I just discovered that this seems device dependent...happens on the Droid X, but not a Samsung Captivate, not on Nexus S, and not the emulator.
推荐答案
有一种方法可以做到这一点 - 比较难看,两层,但仍然是一个解决办法
There is a way to do that - rather ugly, two layered, but still a workaround.
您应该
- 修改的WebView如何处理自动linkifiable项目
-
明确告诉加载的页面没有应用样式和触觉反馈。
- modify how the webview will handle the auto-linkifiable items
explicitly tell the loaded page not to apply styles and haptic feedback.
mWebView.setWebViewClient( new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, final String url) {
Uri uri = Uri.parse(url);
//TODO analyse the uri here
//and exclude phone and email from triggering any action
return false;
}
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {}
public void onPageFinished (WebView view, String url) {...}
public void onPageStarted(WebView view, String url, Bitmap favicon) {...}
public void onLoadResource(WebView view, String url) {...}
});
在HTML指定以下meta标签,在标签内:
In the html specify the following meta tags inside the tag:
<meta name="format-detection" content="telephone=no" />
<meta name="format-detection" content="email=no" />
希望这有助于。
这篇关于禁用web视图的自动Linkify的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!