How to detect single Tap on the WebView
. I am displaying WebView
as a ViewPager
page. So, I can't use OnTouchListener
. And OnClickListener
doesn't work on WebView
.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
If you had a link to get the event you can use something like this with shouldOverrideUrlLoading:
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
try {
String host = null;
if (null != url && null != (host = Uri.parse(url).getHost())) {
if (host.equals("myclikableUrl")) {
clickEvent();
}
return true;
} else {
return false;
}
} catch (Exception e) {
return false;
}
}.....
});
回答2:
Try to crete your own class that extends WebView
and here override dispatchTouchEvent(MotionEvent ev)
. Also you could add GestureDetector
and catch single tap on webview http://developer.android.com/training/gestures/detector.html