2

I've a webview that loads a website from local assets folder:

    webView = (WebView) findViewById(R.id.webView);

    //webView.setInitialScale(1);
    //webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
    //webView.getSettings().setLoadWithOverviewMode(true);
    //webView.getSettings().setUseWideViewPort(true);

    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);

    webView.setWebViewClient(new WebViewClient() {

        public void onPageFinished(WebView view, String url) {
            webView.setVisibility(View.VISIBLE);
        }
    });

    if ((Locale.getDefault().getLanguage()).contains("ar"))
        webView.loadUrl("file:///android_asset/Index-ar.html");
    else
        webView.loadUrl("file:///android_asset/Index-en.html");

By default, the webpage is zoomed in and the user have to scroll and all what I want is to fit the page width to the webview width (which is full screen).

The comments shows you what I've tried:

setInitialScale(1) hides all the content of the page!

setDefaultZoom(WebSettings.ZoomDensity.FAR) changes nothing.

setLoadWithOverviewMode(true) and setUseWideViewPort(true) zooms out to much.

Any suggestions ?

salih kallai
  • 879
  • 2
  • 13
  • 34
Nasser AlSalmi
  • 21
  • 1
  • 1
  • 5

3 Answers3

9

Its little late, but it can help some who needs it.

Add following in head tag of the webpage :

<meta name="viewport" content='width=device-width, initial-scale=1.0,text/html,charset=utf-8' >

Then add this in activity :

WebView webView = (WebView) findViewById(R.id.webView);

webView.setInitialScale(1);

webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);

If you want to support zoom buttons you can add this –

webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setSupportZoom(true);
pratik
  • 211
  • 2
  • 8
4

Could you please try this :

web.getSettings().setBuiltInZoomControls(true);
web.getSettings().setSupportZoom(true); 
web.getSettings().setUseWideViewPort(true);
web.getSettings().setLoadWithOverviewMode(true);
Haresh Chaudhary
  • 4,390
  • 1
  • 34
  • 57
-1

Have you tried to do that by xml? Set layout width and height to fill_parent.

<WebView  
      android:id="@+id/webView"
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"/>
aandrei
  • 165
  • 3
  • 13
  • 1
    I'm using that now. My webview fills the screen with match_parent for width and height. But the issue is on the content of the webview not fitting themselves to the width and height of the webview. – Nasser AlSalmi Mar 13 '16 at 08:44