Search code examples
javaandroidwebviewzooming

Android Webview initial zoom out


I'm using a webview in my android app, at the moment when the app is started the website is zoomed in quite a lot, i want it to be zoomed out to fit the width of the screen. I currently have this in my activity:

super.onCreate(savedInstanceState);
    setContentView(R.layout.shop);
    WebView webview;
    webview = (WebView) findViewById(R.id.webview);
    webview.setWebViewClient(new WebViewClient());
    webview.getSettings().setJavaScriptEnabled(true);
    webview.loadUrl("http://www.example.com");

Solution

  • webview.getSettings().setLoadWithOverviewMode(true);    
    

    This will cause the webview to be zoomed out initially.

    webview.getSettings().setUseWideViewPort(true);
    

    The Webview will have a normal viewport (like desktop browser), when false the webview will have a viewport constrained to it's own dimensions.

    EDIT: With the introduction of "Chrome web view" in Android KitKat, this code might not work.