Thursday, April 12, 2012

Android Webview with transparent background

Yes, it is possible!

           webView.setBackgroundColor(0x00FFFFFF);

However, if in your AndroidManifest.xml contains:

             android:hardwareAccelerated="true"
webView's background, for some reason, does not change to transparency.
(It took me while to figure this out!)

This is how to disable hardware acceleration on the view that contains webview:

             view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

1 comment:

  1. Note that the 'View.setLayerType(...)' method was added in API Level 11 so won't work if you're building for older devices.

    ReplyDelete