0

Recently I was working on an app for Android 2.2 . I am using the same app on android 4.0 But, the webview doesn't displays the images and just shows a white screen.

I have just used simple code:

WebView mWebView2 = (WebView) findViewById(R.id.webViewQ2);
mWebView2.getSettings().setBuiltInZoomControls(true);
mWebView2.getSettings().setJavaScriptEnabled(true);
mWebView1.loadDataWithBaseURL("","<table width=\"100%\"><tr><td style=\"text-align:center; background-color:#c8c8c8;\">Question</td></tr></table>"+answer1, "text/html", "utf-8", "");
mWebView2.loadDataWithBaseURL("","<table width=\"100%\"><tr><td style=\"text-align:center; background-color:#c8c8c8;\">Question</td></tr></table>"+answer2, "text/html", "utf-8", "");

Anyone could help me Please all my code is working fine but this point.

Note:It sometimes automatically shows the images and sometimes doesnt show any thing.

Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
Navdroid
  • 4,453
  • 7
  • 29
  • 47

2 Answers2

1
String htmlContent="<body style="+"text-align:center;"+"><img  src=\""+url+"\"/></body>";
mywebview.loadDataWithBaseURL("not_needed", htmlContent, "text/html", "utf-8", "not_needed");

Use this in your code. It is working for me.

Mairaj Ahmad
  • 14,434
  • 2
  • 26
  • 40
LuminiousAndroid
  • 1,557
  • 4
  • 18
  • 28
0

If you're certain that your HTML isn't malformed, you can try disabling hardware acceleration on the WebView.

As explained here, try the following:

WebView mWebView2 = (WebView) findViewById(R.id.webViewQ2);
myWebView2.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Mr. S
  • 1,469
  • 2
  • 15
  • 27