Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

enable/disable zoom in Android WebView

There are some methods in WebSettings related to zoom:

  • WebSettings.setSupportZoom
  • WebSettings.setBuiltInZoomControls

I noticed they work differently on some devices. For example, on my Galaxy S pinch to zoom is enabled by default, but on LG P500 it is disabled (And now I don't know how to enable ONLY pinch to zoom, but hide zooming buttons).

On P500 when I call setBuiltInZoomControls(true) I get both these variants working (multitouch and buttons).

How to enable multitouch zoom and disable zooming buttons on devices such an LG P500? (Also, I know the same problems are on HTC devices)

UPDATE: Here is almost full code for the solution

if (ev.getAction() == MotionEvent.ACTION_DOWN ||         ev.getAction() == MotionEvent.ACTION_POINTER_DOWN ||         ev.getAction() == MotionEvent.ACTION_POINTER_1_DOWN ||         ev.getAction() == MotionEvent.ACTION_POINTER_2_DOWN ||         ev.getAction() == MotionEvent.ACTION_POINTER_3_DOWN) {     if (multiTouchZoom && !buttonsZoom) {         if (getPointerCount(ev) > 1) {             getSettings().setBuiltInZoomControls(true);             getSettings().setSupportZoom(true);         } else {             getSettings().setBuiltInZoomControls(false);             getSettings().setSupportZoom(false);         }     } }  if (!multiTouchZoom && buttonsZoom) {     if (getPointerCount(ev) > 1) {         return true;     } } 

This code is in my onTouchEvent overridden method of the WebView.

like image 452
Eugene Nacu Avatar asked Feb 26 '11 08:02

Eugene Nacu


People also ask

How do I enable zoom in WebView?

webSettings. setBuiltInZoomControls(true); webSettings. setSupportZoom(true);

How do I zoom out in WebView Android?

getSettings(). setBuiltInZoomControls(true); per this answer to default my view to zoomed out and to be able to pinch-to-zoom.

How do I disable zoom in react native WebView?

Show activity on this post. How to disable zoom on react-native web-view ,is there a property like hasZoom={false} (just an example) that can be included in the below web-view tag that can disable zooming.

What is zoom control in Android?

In Android, Zoom Control is a class that has some set of methods that are used to control the zoom functionality. It has two buttons that are used to control the zoom functionality (ie Zoom In and Zoom Out). Zoom Control Class has been deprecated in API Version 29.


1 Answers

On API >= 11, you can use:

wv.getSettings().setBuiltInZoomControls(true); wv.getSettings().setDisplayZoomControls(false); 

As per the SDK:

public void setDisplayZoomControls (boolean enabled)  

Since: API Level 11

Sets whether the on screen zoom buttons are used. A combination of built in zoom controls enabled and on screen zoom controls disabled allows for pinch to zoom to work without the on screen controls

like image 111
yuttadhammo Avatar answered Sep 21 '22 02:09

yuttadhammo