Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView Rendering Issue in Android KitKat

I've been working on an application which have a WebView in which a static page get loaded from the assets (Also using JavaScript). This WebView is not working in KitKat, it remains blank. I am aware of the change in rendering engine (webkit to chromium) which happened in WebView in kitkat and tried the steps for migrating, which is given in Android Developers page. But it didn't help.

In logcat I am getting an error which is thrown from the Chromium source.

W/AwContents﹕ nativeOnDraw failed; clearing to background color.

Please suggest a workaround.

like image 786
gnuanu Avatar asked Dec 19 '13 07:12

gnuanu


3 Answers

In my case, in Android 4.4, I was getting a black background no matter I set what and this error message in my LogCat: nativeOnDraw failed; clearing to background color.

From Googling, it seems to be because hardware accelerated canvas rendering is not supported in Chromium WebView. I added this line to the WebView to turn off hardware accelerated canvas and now it works.

mWebview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
like image 120
georgiecasey Avatar answered Nov 20 '22 20:11

georgiecasey


I ran into the same issue, but I did find a workaround. All you have to do is explicitly set a CSS background for your webpage. Like so:

body {
  background: white;
}

As it turns out if you do not explicitly set a background for a webpage the WebView will fail to draw said background and you'll end up with a transparent WebView.

like image 6
DataDino Avatar answered Nov 20 '22 21:11

DataDino


This seems to be a chromium webview bug.

Here is a thread about the issue: https://jira.appcelerator.org/browse/TIMOB-16479

Apparently, the accepted answer is not a sure fix. A workaround is mentioned in the link.

like image 4
Tore Rudberg Avatar answered Nov 20 '22 19:11

Tore Rudberg