Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"body background-color: transparent" did not affect on webview of android 4.0.3

I want to display webView on static image on imageView.

I set transparent color to webView like this

webview.setBackground(0);

I set background-color as transparent

<html>
<head>
</head>
<body style="background-color:transparent">
</body>
</html>

but Webview's background keep displaying as white.

I show any questions and try these following page's solution but nothing to change.

  • Android WebView style background-color:transparent ignored on android 2.2
  • Transparent Background + Flash in WebView on Android 3.0+?

Do you have any ideas? Please help me.

like image 938
user1153942 Avatar asked Jan 17 '12 13:01

user1153942


2 Answers

I ran into the same problem with the white WebView background on a device with ICS (4.0)!

The answer from NcJlee did remove the white background from the webview, but it requires API level 11! It will not work on older API's!

    webView.setBackgroundColor(0);
    webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);

The solution is to set a android:layerType="software" attribute on the webview in the .xml layout resource.

    <WebView
        android:id="@+id/webviev"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:layerType="software" />
like image 55
TouchBoarder Avatar answered Nov 04 '22 03:11

TouchBoarder


One way to avoid this is to uncheck "Force GPU Rendering" in

    Settings -> Developer Options -> Force GPU Rendering

But that doesn't solve the problem. I've tried this code in emulator and it works. By forcing the webview to render by using software instead of hardware acceleration.

    webview.setBackgroundColor(Color.TRANSPARENT);
    webview.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);

Does it solve your problem?

like image 23
NcJlee Avatar answered Nov 04 '22 05:11

NcJlee