禁用Webview的自动Linkify [英] Disable the automatic Linkify of Webview

查看:29
本文介绍了禁用Webview的自动Linkify的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在创建的网络视图.它似乎会自动将数字链接到 tel: urls.我没有看到删除此功能的方法(至少与在 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).

代码非常简单:

// 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.

你应该

  1. 修改 webview 如何处理可自动链接的项目
  2. 明确告诉加载的页面不要应用样式和触觉反馈.

  1. modify how the webview will handle the auto-linkifiable items
  2. 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 中,在标签内指定以下元标签:

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" />

希望这会有所帮助.

这篇关于禁用Webview的自动Linkify的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆