4

I'm currently trying to enable native viewport zoom (like the native web zoom I mean) on Cordova Android (webview).

Here's my viewport tag :

 <meta name="viewport" content="user-scalable=yes, initial-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />

And I tried something like this :

         function onDeviceReady() {


                ImgCache.options.chromeQuota = 50*1024*1024;

                var domElement = document.getElementById('main-html');
                angular.bootstrap(domElement, "myApp");

                webView.getSettings().setBuiltInZoomControls(true); // this line

            }

As said there : How to enable zoom controls and pinch zoom in a WebView?

But it doesn't work. What I am missing ?

Community
  • 1
  • 1
enguerranws
  • 8,087
  • 8
  • 49
  • 97

1 Answers1

1

Try this.

put following in your index.html

<meta name="viewport" content="user-scalable=yes, initial-scale=1, maximum-scale=2, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />

put following in the onCreate method of your main Android Java File inside src/com/packagename directory:

super.appView.getSettings().setBuiltInZoomControls(true);
super.appView.getSettings().setDefaultZoom(ZoomDensity.MEDIUM); 
super.appView.getSettings().setSupportZoom(true);

also add following packages in your main java file:

import android.webkit.WebSettings; 
import android.webkit.WebSettings.ZoomDensity;

Hope this helps...

  • Sure it helps ! Thank you ! Note that : 'super.appView.getSettings().setDefaultZoom(ZoomDensity.MEDIUM);' made an error on compilation, so I commented it. – enguerranws Jun 26 '14 at 12:21
  • Great. Sorry about the error. Updated the answer with missing packages. there should not be any errors now :) – Jagat Kothari Jun 26 '14 at 12:23
  • Anyone seeing this in 2019 on may need to use a webview object instead of `super.appView` which you can get using `WebView webView = (WebView) appView.getEngine().getView();` as shown in [this comment.](https://stackoverflow.com/a/36464728/7407567) – Andrew Dant May 24 '19 at 17:17