9Answers
  • 3
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Set zoom for Webview

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

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);
  • 35
Reply Report

setDefaultZoom is deprecated.

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

So instead of that you can use like below,

webview.setInitialScale(1);
webview.getSettings().setLoadWithOverviewMode(true); 
webview.getSettings().setUseWideViewPort(true);

This help you to remove

setDefaultZoom(WebSettings.ZoomDensity.FAR).
  • 22
Reply Report

@John gave the right idea, but one command is enough, since you can get and set before the page shows:

private class MyWebViewClient extends WebViewClient {
    public void onPageFinished(WebView view, String url) {
        view.setInitialScale((int)(100*view.getScale()));
    }
}

then just set this as your WebView's client:

webview.setWebViewClient(new MyWebViewClient());
  • 4
Reply Report
      • 2
    • I'm using a Marshmallow tablet and could not for the life of me get the page to scale to the size of the webview... that is until I read your post. I used your code except for one change because .getScale() is deprecated: view.setInitialScale((int)(100*view.getScaleY()));

try this thing

int default_zoom_level=100;
Point Scroll=new Point(0,0);
webview1.setInitialScale(default_zoom_level);
    webview1.loadData("url");

After doing zoomIn/ZoomOut or Scrolling.Since Scale may be get to change so calculate scale level and scrolling along X and Y Axis.

int current_scale_level=(int)webview1.getScale()*100;
Scroll.x=webview1.getScrollX();
Scroll.y=webview1.getScrollY();

then before loading of next webview do this

webview2.setInitialScale(current_scale_level);
    webview2.loadData("url");
webview2.scrollTo(Scroll.x,Scroll.y);
  • 2
Reply Report

I found this blog helpful:

It will help you set initial zoom level and on seek-change content of webview resizes

// Set the initial progress of seek bar mSeekBar.setProgress(mWebView.getSettings().getTextZoom()/25);

    // Set a change listener for seek bar
    mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            /*
                public abstract void setTextZoom (int textZoom)
                    Sets the text zoom of the page in percent. The default is 100.

                Parameters
                    textZoom : the text zoom in percent
            */

            // Zoom the web page text
            // We will allow text zooming 25% to 300%
            mWebView.getSettings().setTextZoom(i*25);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

http://android--code.blogspot.in/2016/01/android-how-to-change-webview-text-size.html

  • 0
Reply Report