I am looking for a solution to disable one-touch-zoom (also known as drag-to-zoom or double-tap-drag to zoom) for Android WebView. In case you are not familiar with the gesture: you double tap the screen in WebView, and upon your second tap, you keep your finger on the screen and drag it up-down which makes WebView zoom.
The application is in Xamarin C#, using WebView.
The following code disables only the other type of zooms (double click, pinch and zoom):
Settings.SetSupportZoom(false);
Settings.BuiltInZoomControls = false;
Any help would be much appreciated.
This feature isn't automatically enabled for a webview. I think the problem itself lies in the website. I do have a fix though.
Add a touchEvent to the webview. You can disable any form of interaction with the webview by setting e.Handled to true.
I'm keeping track of e.Handled through the "handled" variable. It get's set to true when you double tap and gets put back to false when you release your finger of the screen. This causes the webview to not do anything after a double tap, until you remove your finger of the screen.
var handled = false;
GestureDetector _gestureDetector = new GestureDetector(this, new GestureListener());
_gestureDetector.DoubleTap += (object sender, GestureDetector.DoubleTapEventArgs e) => {
handled = true;
};
webView.Touch += (object sender, View.TouchEventArgs e) => {
_gestureDetector.OnTouchEvent(e.Event);
if (e.Event.Action == MotionEventActions.Up)
{
handled = false;
}
e.Handled = handled;
};
You need to add this class to enable the OnDoubleTap feature.
private class GestureListener : GestureDetector.SimpleOnGestureListener
{
public override bool OnDoubleTap(MotionEvent e)
{
return true;
}
}