Android Webview not rendering correctly on ICS 4.0 +
Asked Answered
E

2

3

I have a problem with an Android app I am working on.

I loaded a locally stored HTML into a WebView and set:

webSettings.setLoadWithOverviewMode(true);

webSettings.setUseWideViewPort(true);

webSettings.setJavaScriptEnabled(true);

It works great, but just not on ICS 4.0+.

Any ideas what to do?

Here are some screenshots to document the error:

Correct layout Broken layout

Thanks in advance

Erdda answered 31/10, 2012 at 8:54 Comment(0)
M
1

Give this a try:

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

switch (metrics.densityDpi) {
case DisplayMetrics.DENSITY_HIGH:
    webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
    break;

case DisplayMetrics.DENSITY_MEDIUM:
    webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
    break;

case DisplayMetrics.DENSITY_LOW:
    webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.CLOSE);
    break;

default:
    webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
    break;
}

See original post

OR Have you tried this?

WebView webview1 = (WebView) findViewById(R.id.webview1);
webview1.setInitialScale(90);
webview1.loadUrl("http://stackoverflow.com");
Maressa answered 31/10, 2012 at 9:9 Comment(2)
Thanx for the tip. Unfortunatly it did not make any differenceErdda
@Erdda I have updated the answer, give this a try. Also, tell me is your problem device specific or just Android version specific?Maressa
S
0

To me this looks more like a styling issue in your CSS code. Try playing around with the width sizes.

You might want to load a difference css for viewing it on a mobile device.

Seedbed answered 15/5, 2015 at 2:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.