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

4

9

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.

Do you have any ideas? Please help me.

Madness answered 17/1, 2012 at 13:19 Comment(1)
This issue is fixed in Android 4.1.1.Puente
W
11

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" />
Wernher answered 25/2, 2012 at 22:32 Comment(1)
On ICS, I just had to disable "Force GPU Rendering" in the system settings like NcJiee mentioned, and then setBackgroundColor to Color.TRANSPARENT. However, I had to remove setLayerType statement, which is not available on API level 10.Lethalethal
I
5

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?

Indention answered 6/2, 2012 at 5:18 Comment(0)
D
0

try this code to transprent webview

webView.setBackgroundColor(Color.TRANSPARENT);
Deliquesce answered 29/12, 2012 at 7:10 Comment(0)
M
0

attempts to invoke setLayerType or specify android:layerType in xml caused compilation errors for me. This happened despite setting minSdkVersion or targetSdkVersion to 11+.

So, I ended up using reflection to call setLayerType as recommended in: Transparent WebView not working on Android v4.0

Mcgehee answered 2/1, 2013 at 3:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.