Some background to this question is here. It relates to working around a known bug in Android where the WebView background needs to be transparent. Android WebView style background-color:transparent ignored on android 2.2
It involves a WebView, hosting an HTML document with a transparent background, so the WebView is transparent and the HTML document can be overlaid onto other views.
Adding the following method to the WebView subclass and calling it from the constructor works for me on Android v2, v3, and v4, EXCEPT when the pixel height of the WebView is larger than the screen height in pixels (e.g. the WebView is in a ScrollView, so longer than the screen).
protected void setBackgroundToTransparent() {
this.setBackgroundColor(Color.TRANSPARENT);
this.setBackgroundDrawable(null);
if (Build.VERSION.SDK_INT >= 11) // Android v3.0+
try {
Method method = View.class.getMethod("setLayerType", int.class, Paint.class);
method.invoke(this, 1, new Paint()); // 1 = LAYER_TYPE_SOFTWARE (API11)
} catch (Exception e) {}
}