Try to search your question here, if you can't find : Ask Any Question Now ?

Android WebView with layer_type_software not showing HTML5 canvas content

HomeCategory: stackoverflowAndroid WebView with layer_type_software not showing HTML5 canvas content
Avatargaurav asked 2 weeks ago

Since last update of Android WebView a web page with a HTML5 canvas is not displayed correctly when hardware acceleration is disabled by setting the WebView’s layer type to View.LAYER_TYPE_SOFTWARE. Is there a workaround for this problem?

When I leave out the following line of Java code:
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Then the Content is displayed correctly.

Java code:

WebView webView = findViewById(;
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

Html file test.html:

<!DOCTYPE html>
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
// Create gradient
var grd = ctx.createLinearGradient(0,0,200,0);
// Fill with gradient
ctx.fillStyle = grd;

Expected result:
Red linear gradient in black border

Actual result:
Empty black border

1 Answers
Best Answer
AvatarMatthias answered 2 weeks ago
Your Answer

8 + 4 =

Popular Tags

WP Facebook Auto Publish Powered By :