I'm struggling to create a WebView with transparent background.
webView.setBackgroundColor(0x00FFFFFF);
webView.setBackgroundDrawable(myDrawable);
Then I load a html page with
<body style="background-color:transparent;" ...
The background color of the WebView is transparent but as soon as the page is loaded, it's overwritten by a black background from the html page. This only happens on android 2.2, it works on android 2.1.
So is there something to add in the html page code to make it really transparent ?
This is how you do it:
First make your project base on 11, but in AndroidManifest set minSdkVersion to 8
android:hardwareAccelerated="false" is unnecessary, and it's incompatible with 8
For safety put this in your style:
worked for me on 2.2 and 4
The most important thing was not mentioned.
The html must have a
body
tag withbackground-color
set totransparent
.So the full solution would be:
HTML
Activity
webView.setBackgroundColor(Color.TRANSPARENT)
before or afterloadUrl()
/loadData()
.android:hardwareAccelerated="false"
in the manifest.Tested on IceCream Sandwich
Try
webView.setBackgroundColor(0);
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
below code works fine Android 3.0+ but when you try this code below android 3.0 then your app forcefully closed.
You try below code on your less then API 11.
Or
you can also try below code which works on all API fine.
above code use full for me.