Reputation: 305
I need a WebView to be transparent, but can't find solution
I've found only
webView.setBackgroundColor(0x00000000);
webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
, but this is only for Honeycomb and older and I need my App to work on 2.x also. None of the solutions I've found on stackoverflow are working- webView is still white.
Can anyone tell me what's working for sure for pre-Honeycomb versions?
maybe I should change something in html as well?
Upvotes: 0
Views: 171
Reputation: 2290
I had written a helper method to do that and it seems to work the majority of the time, setting the background color to transparent for all versions and changing the layer type where available...
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SuppressLint("NewApi")
public static void clearWebViewBackground (final WebView webView) {
webView.setBackgroundColor(0x00FFFFFF);
webView.setWebViewClient(new myWebViewClient());
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
webView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
}
}
Upvotes: 0
Reputation: 11194
This worked for me : myWebView.setBackgroundColor(Color.TRANSPARENT);
OR add as part of html here is my code snip :
String css = "<head><style >* {word-wrap: break-word;margin:0;padding:0;font-size:15px; text-align:justify;font-family: Arial, Helvetica, sans-serif}</style></head>";
myWebView.loadData(css, "text/html", null);
myWebView.setBackgroundColor(Color.TRANSPARENT);
Upvotes: 1