Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Double Tap Zoom/Unzoom on a webview

On Android, I'm am using a webview to display a chart designed by the API flot.

I'm using this code:

    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.graphique);

    // Get a reference to the declared WebView holder
    WebView webview = (WebView) this.findViewById(R.id.webView1);

    // Get the settings
    WebSettings webSettings = webview.getSettings();

    // Enable Javascript for interaction
    webSettings.setJavaScriptEnabled(true);

    // Make the zoom controls visible
    //webSettings.setBuiltInZoomControls(true);

    // Allow for touching selecting/deselecting data series
    webview.requestFocusFromTouch();

    // Set the client
    webview.setWebViewClient(new WebViewClient());
    webview.setWebChromeClient(new WebChromeClient());
    webview.setBackgroundColor(0);

    webview.getSettings().setLoadWithOverviewMode(true);
    webview.getSettings().setUseWideViewPort(true);
    // Load the URL
    webview.loadUrl("file:///android_asset/graph.html");

The graph is displayed correctly and fills the entire webview even if the width and height are not the same at start (thanks to setLoadWithOverviewMode(true) and setUseWideViewPort(true)).

But the user can still zoom and unzoom the graph by double tapping on it.

I want to prevent this action, I tried to put my webview to clickable=false, focusable=false and focusableintouchmode=false but it doesn't work.

I tried this also :

webview.getSettings().setBuiltInZoomControls(false);

But it doesn't work. Do you have any clue ?

like image 665
Thordax Avatar asked Jan 26 '12 13:01

Thordax


People also ask

How do I turn off double touch zoom?

Tap anywhere on the screen, except the keyboard or navigation bar. Drag 2 fingers to move around the screen. Pinch with 2 fingers to adjust zoom. To stop magnification, use your magnification shortcut again.

How do I turn off double tap zoom on Chrome?

In future versions of Chrome for Android, the double tap will be removed when you have a viewport set. If you want to disable it for stable today, you will need to set user-scalable=no in your viewport. This will disable zooming (which may be bad for accessibility) but should allow you to get all touch events.


1 Answers

try to set

webView.getSettings().setUseWideViewPort(false);

and deal with scale manually to fit the width..

like image 189
Maher Abuthraa Avatar answered Sep 21 '22 05:09

Maher Abuthraa