How to enable zoom controls and pinch zoom in a WebView?

前端 未结 6 1120
醉酒成梦
醉酒成梦 2020-12-02 10:46

The default Browser app for Android shows zoom controls when you\'re scrolling and also allows for pinch zooming. How can I enable this feature for my own Webview?

I

相关标签:
6条回答
  • 2020-12-02 11:13

    Try this code, I get working fine.

     webSettings.setSupportZoom(true);
     webSettings.setBuiltInZoomControls(true);
     webSettings.setDisplayZoomControls(false);
    
    0 讨论(0)
  • 2020-12-02 11:17

    Strange. Inside OnCreate method, I'm using

    webView.getSettings().setBuiltInZoomControls(true);
    

    And it's working fine here. Anything particular in your webview ?

    0 讨论(0)
  • 2020-12-02 11:23

    Use these:

    webview.getSettings().setBuiltInZoomControls(true);
    webview.getSettings().setDisplayZoomControls(false);
    
    0 讨论(0)
  • 2020-12-02 11:27

    To enable zoom controls in a WebView, add the following line:

    webView.getSettings().setBuiltInZoomControls(true);
    

    With this line of code, you get the zoom enabled in your WebView, if you want to remove the zoom in and zoom out buttons provided, add the following line of code:

    webView.getSettings().setDisplayZoomControls(false);
    
    0 讨论(0)
  • 2020-12-02 11:32

    Check if you don't have a ScrollView wrapping your Webview.

    In my case that was the problem. It seems ScrollView gets in the way of the pinch gesture.

    To fix it, just take your Webview outside the ScrollView.

    0 讨论(0)
  • 2020-12-02 11:39

    Inside OnCreate, add:

     webview.getSettings().setSupportZoom(true);
     webview.getSettings().setBuiltInZoomControls(true);
     webview.getSettings().setDisplayZoomControls(false);
    

    Inside the html document, add:

    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2, user-scalable=yes">
    </head>
    </html>
    

    Inside javascript, omit:

    //event.preventDefault ? event.preventDefault() : (event.returnValue = false);
    
    0 讨论(0)
提交回复
热议问题