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 ?
Just use these lines .....
And remember a point that Always set background color after loading data in webview.
At the bottom of this earlier mentioned issue there is an solution. It's a combination of 2 solutions.
When adding this code to the WebViewer after loading the url, it works (API 11+).
It even works when hardeware acceleration is ON
If webview is scrollable:
Add this to the Manifest:
OR
Add the following to WebView in the layout:
Add the following to the parents scroll view:
I was trying to put a transparent HTML overlay over my GL view but it has always black flickering which covers my GL view. After several days trying to get rid of this flickering I found this workaround which is acceptable for me (but a shame for android).
The problem is that I need hardware acceleration for my nice CSS animations and so
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
is not an option for me.The trick was to put a second (empty)
WebView
between my GL view and the HTML overlay. ThisdummyWebView
I told to render in SW mode, and now my HTML overlays renders smooth in HW and no more black flickering.I don't know if this works on other devices than My Acer Iconia A700, but I hope I could help someone with this.
I had the same issue with 2.2 and also in 2.3. I solved the problem by giving the alpa value in html not in android. I tried many things and what I found out is
setBackgroundColor();
color doesnt work with alpha value.webView.setBackgroundColor(Color.argb(128, 0, 0, 0));
will not work.so here is my solution, worked for me.
And in Java,
And here is the Output screenshot below.![enter image description here](https://i.stack.imgur.com/zgPjA.png)
Try webView.setBackgroundColor(Color.parseColor("#EDEDED"));