Android Webview Style Background-Color:Transparent Ignored on Android 2.2

Android WebView style background-color:transparent ignored on android 2.2

Actually it's a bug and nobody found a workaround so far. An issue has been created. The bug is still here in honeycomb.

Please star it if you think it's important : http://code.google.com/p/android/issues/detail?id=14749

WebViewClient - transparent background for later OS versions

It turns out that the above code WAS in fact making the WebView transparent and that the black surround that I was seeing was actually the default background of the pseudo-body of the rendered page when the page contains only an image. (This answer gave me the clue!)

The trick, therefore was to create an HTML page on the fly with a transparent body and include the image in that page rather than just loading the image into the WebView directly.

So, using:

wv.setBackgroundColor(Color.TRANSPARENT)
wv.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null)

in the onPageFinished method AND using

String myHTML = "<html><body style=\"background: transparent; margin:0; padding:0;\"><img src=\"" +
myImgURL + "\"></body></html>";
wv.loadData(myHTML, "text/html", "UTF-8");

Has achieved the desired effect of displaying the image in the WebView as though it were directly on the canvas.

(Note that I have tried with and without the setLayerType line and it still works in Oreo - it may or may not be needed in other versions)

Android WebView background color

Try using synopsis.getSettings();

WebView synopsis;
synopsis=(WebView)findViewById(R.id.synopsis);
synopsis.setBackgroundColor(Color.TRANSPARENT);

WebView shows transparent color while navigating back to Webview from next screen on ICS (Android 4)

After many tries found it was device issue!!.. :(

Semi-Transparent background color in WebView in Android

After searching on the stackoverflow I've seen that its not only having this issue, and I found a work around for the devies 2.2xx and 2.3xx here is the link below..

Here is the link to my Solution.



Related Topics



Leave a reply



Submit