Enable Zoom Option In Webview Android
I am developing the application using PhoneGap. I cannot enable built in zoom in/out in the webview. I used Following code in onCreate Function WebView web = (WebView) findViewById
Solution 1:
Check if you don't have a ScrollView wrapping your Webview.
It seems ScrollView gets in the way of the pinch gesture.
To fix it, just take your Webview outside the ScrollView nd then use the same line:
webSettings.setBuiltInZoomControls(true);
webSettings.setSupportZoom(true);
Solution 2:
For Cordova 5
This has changed slightly for Cordova 5.1 (I think it changed with 5.0 actually). To enable Android zooming for Cordova 5, add these lines :
import android.webkit.WebView;
import android.webkit.WebSettings;
import android.webkit.WebSettings.ZoomDensity;
and these
WebViewwebView= (WebView) appView.getEngine().getView();
WebSettingssettings= webView.getSettings();
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
A full sample of your src/com/YOURPACKAGE.java
file:
package com.YOURPACKAGE;
import android.os.Bundle;
import org.apache.cordova.*;
import android.webkit.WebView;
import android.webkit.WebSettings;
import android.webkit.WebSettings.ZoomDensity;
publicclassMainActivityextendsCordovaActivity
{
@OverridepublicvoidonCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
WebViewwebView= (WebView) appView.getEngine().getView();
WebSettingssettings= webView.getSettings();
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
//settings.setDefaultZoom(ZoomDensity.FAR);
}
}
Solution 3:
Use ==>>
web.getSettings().setBuiltInZoomControls(true);
before the line ==>>
web.loadDataWithBaseURL("Your Required params");
Post a Comment for "Enable Zoom Option In Webview Android"