Set zoom for Webview

前端 未结 9 1097
忘了有多久
忘了有多久 2020-11-30 02:26

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. Righ

相关标签:
9条回答
  • 2020-11-30 03:09

    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 讨论(0)
  • 2020-11-30 03:15

    You can set the zoom to 0.1f

    mWebView.zoomBy(0.1f);

    0 讨论(0)
  • 2020-11-30 03:16

    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).
    
    0 讨论(0)
提交回复
热议问题