WebView Disable DoubleTap

2019-08-11 00:51发布

问题:

I am developing an android application and successfully disabled zoom-in, zoom-out by swiping. But I have failed to disable double tap zooming. Is there an obvious function to use? Thanks.

Here is my code,

webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setBuiltInZoomControls(false);
webview.getSettings().setDisplayZoomControls(false);
webview.getSettings().setSupportZoom(false);
webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
webview.loadUrl(url1);

回答1:

Unfortunately, it's a "feature" in WebView in pre-KitKat versions of Android, that double tap can be explicitly disabled only by turning off UseWideViewPort setting.

There are workarounds that based on "stealing" double tap events from WebView described in WebView getting rid of double tap zoom. and How to disable doubletap zoom in android webview?



回答2:

add this

webView.getSettings().setUseWideViewPort(false);