Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set zoom for Webview

Tags:

android

I have a WebView and 2 urls to open it it. What I want to do is, when i set a zoom level for 1st url, and then i go to 2nd url, it should also have the same zoom level. Right now, the zoom level resets for both.

Thanks, Farha

like image 396
Farha Ansari Avatar asked Mar 24 '10 04:03

Farha Ansari


People also ask

How to set zoom in webview android?

This example demonstrate about How to enable webview zoom controls in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do I enable zoom in Webview?

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

How do I zoom out in Webview Android?

webview. getSettings(). setLoadWithOverviewMode(true); This will cause the webview to be zoomed out initially.


2 Answers

this will be applicable in this scenario i believe

mWebView.setInitialScale(ZOOM_LEVEL); 

where ZOOM_LEVEL for example can be 25 for 25% 150 for 150%

like image 179
Samuel Avatar answered Sep 22 '22 03:09

Samuel


use the webSettings class

webview.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR); 

Notice that although webSettings is available since API Level 1, WebSettings.ZoomDensity is available since API Level 7. Works well for all device resolutions.

Also, in order to enable zoom on the webView, add the following code:

webView.getSettings().setBuiltInZoomControls(true); 
like image 38
Praveen Avatar answered Sep 20 '22 03:09

Praveen