enable/disable zoom in Android WebView
I've looked at the source code for WebView
and I concluded that there is no elegant way to accomplish what you are asking.
What I ended up doing was subclassing WebView
and overriding OnTouchEvent
.
In OnTouchEvent
for ACTION_DOWN
, I check how many pointers there are using MotionEvent.getPointerCount()
.
If there is more than one pointer, I call setSupportZoom(true)
, otherwise I call setSupportZoom(false)
. I then call the super.OnTouchEvent().
This will effectively disable zooming when scrolling (thus disabling the zoom controls) and enable zooming when the user is about to pinch zoom. Not a nice way of doing it, but it has worked well for me so far.
Note that getPointerCount()
was introduced in 2.1 so you'll have to do some extra stuff if you support 1.6.
Disable webview zoom in android
wv.getSettings().setSupportZoom(false);
setBuiltInZoomControls it won't disable multitouch zooming but this does.
How to disable one-touch-zoom in Android WebView?
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;
}
}
How to remove zoom buttons on Android webview?
Finally my answer is, Its not possible to hide/remove these button's on WebView
in Android 2.3.
Disable zoom when clicking on form fields within a WebView?
This issue has been fixed by a firmware update on HTC devices, it was (apparently) being caused by the Sense UI overriding default Android functionality incorrectly.
It is very difficult to provide information on exactly when this was corrected, however my web application no longer zooms when a text box is clicked on any HTC device with the latest firmware.
The following two lines of code will disable the "zoom" aspects of an android webview:
// disables the actual onscreen controls from showing up
mWebView.getSettings().setBuiltInZoomControls(false);
// disables the ability to zoom
mWebView.getSettings().setSupportZoom(false);
Disable zoom on web-view react-native?
Thought this might help others, I solved this by adding the following in the html <head>
section:
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0">
Related Topics
How to Make Constraintlayout Work with Percentage Values
Using Global Exception Handling on Android
Edittext: Disable Paste/Replace Menu Pop-Up on Text Selection Handler Click Event
Fool-Proof Way to Handle Fragment on Orientation Change
Android: Viewpager and Horizontalscrollview
I am Getting Imei Null in Android Q
Losing Data When Rotate Screen
Android Emulator Error Message: "Panic: Missing Emulator Engine Program for 'X86' Cpus."
Display Back Button on Action Bar
How to Define Different Dependencies for Different Product Flavors
Google Signin Not Working in Release Mode APK Android
Detect an Application Is Installed or Not
The Signing Fingerprint You Specified Is Already Used by Another Android Oauth2 Client
Android Eclipse Ddms - Can't Access Data/Data/ on Phone to Pull Files
How to Fix "Unexpected Element <Queries> Found in <Manifest>" Error