I read many tickets on the topic of Zooming in WebViews and didnt came to an answer for my case.
Here´s my setup:
I´m using a custom webview with generally these settings:
getSettings().setBuiltInZoomControls(false);
getSettings().setSupportZoom(false);
getSettings().setUseWideViewPort(true);
getSettings().setLoadWithOverviewMode(true);
Let me note right here that i depend on OverviewMode and as well on WideViewPort to Scale my WebView.
I´m also Overriding my OnTouchEvent and and delegate all suitable events to an Gesture detector:
@Override
public boolean onTouchEvent(MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) return true;
return super.onTouchEvent(event);
}
Here is its listeners implementation which is intercepting all doubleTap events:
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
// Do nothing!
return true;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
// Do nothing!
return true;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
// Do nothing!
return true;
}
Also i overrode these 2 WebView methods related to zoom:
@Override
public boolean zoomIn() {
return true;
}
@Override
public boolean zoomOut() {
return true;
}
Notherless of all these options a certain tap frequence will cause my webview to zoom in/out. I havent found an option that disables this kind of zooming, the MotionEvent for this Zoom doesnt seem to be applicable for the GestureDetector and the override zoomIn() zoomOut() methods have no effect either.
Can anyone help me out with a way to avoid this double tap zoom behaivior of WebView?
Another approach (the only one that worked for me) would be to simulate distant intermediate taps between double taps so that the WebView doesn't recongnize them as consequent. Negative coordinates can be used for this purpose, although anything less than -1 would slow down or even break the process. So we need at least two points, say (0, -1) and (2*d+1, -1) where d is the maximum distance between taps for them to be considered double tap.
There's a fantastic solution for your issue, based on Javascript (so you'll have to have access to the HTML/JS code in the remote side, if it's the case).
Using the FastClick library, all you need to do is to add the .js file and then call it:
This will get rid of the double tap zoom, and there's still (in my opinion) a huge bonus: all taps get 0.3 seconds faster, due to the fact the system doesn't have to wait anymore for a double tap! Check this example on Android to see the difference: Practical Example
Well, I don't know if this solution will fit in your case, but it was a perfect solution for my Webview projects. Hope it helps!
ps1: you have to add the code above in all pages and frames
ps2: the pinch zoom will keep working normally
There are two methods to achieve your goal:
Method 1
Implement the
GestureDetector.OnDoubleTapListener
like this:and attach it to your
GestureDetector
like this:Method 2
You can also use the
WebSettings.setUseWideViewPort(false);
and calculate the size of your view manually.These methods should help you to achieve non-zoomable webviews that display everything.
Try making the return values of onDoubleTapEvent onDoubleTap as false....
You need to override OnTouchListener on your WebView by
and inside method onTouch just check that if it detect double tab then ignore the zoom in webview by force to return true
You can see full code like this: MainActivity.java
and activity_main.xml
don't forget to add permission in manifest.xml
If possible, replace the static meta tag in your html:
Additionally you can use a nice script: FastClick
It won't wait for tap events so its faster.
Then set a double tap listener to your gesture detector. (in custom WebView)
Override the onTouchEvent method (in custom WebView):