How to set transparent color in android webview?
<div style="background-color: black" >test</div>
How can I make black color to be transparent for the whole page (like chromakey)?
How to set transparent color in android webview?
<div style="background-color: black" >test</div>
How can I make black color to be transparent for the whole page (like chromakey)?
I've found the solution. I've reimplemented OnDraw method of WebView
@Override
protected void onDraw(android.graphics.Canvas canvas) {
super.onDraw(canvas);
Paint p = new Paint();
p.setARGB(255, 0, 0, 0);
int removeColor = p.getColor();
p.setAlpha(1); // if Alpha is 0 it doesn't work. I don't know why
p.setXfermode(new AvoidXfermode(removeColor, 0, AvoidXfermode.Mode.TARGET));
canvas.drawPaint(p);
}
Had the same problem with the WebView, as it behaved randomly across different OS versions. Finnlay I fixed it with this code this after the loadDataWithBaseURL() call:
I figure this will give the device something to draw, so various caching mechanisms will not kick in. But the result is practically the same as with total transparency, as it is undetectable by average human eye.
No performance penalties noticed as well.
Tested on several devices ranging from 2.2 to 4.2.
Cheers