jax jax - 5 months ago 10
Android Question

setBackgroundColor() in Webview is not working

I have created a webview with a transparent background.

browser = new WebView(ActivityActivate.this);
browser.setBackgroundColor(0);
browser.getSettings().setJavaScriptEnabled(true);
browser.addJavascriptInterface(new JavascriptInterface(), "javaInterface");
browser.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
browser.getSettings().setSupportZoom(true);
browser.loadDataWithBaseURL("https://checkout.google.com", form, "text/html", "UTF-8", null);
llPaymentButtons.addView(browser);


Here is the JavaInterface that should change the color of the background when the html form is submitted and all the checkboxes pass the test.

/**
* Interface for Javascript communication
*/
private class JavascriptInterface {

//This is in fact used but from JavaScript
@SuppressWarnings("unused")
public boolean checkboxPass() {
if( acceptsConditions() && acceptsLicense() && acceptsRefundPolicy() ) {
browser.setBackgroundColor(Color.WHITE);
return true;
}
return false;
}
}


This does not work however, and the returned document still has a transparent background. What am I doing wrong, it seems that
browser.setBackgroundColor(Color.WHITE);
does nothing?

Answer

you can override webview background with setbackgroundResource method,

try like this you will get it,

wv.setBackgroundColor(0);
wv.setBackgroundResource(color.blue);
wv.loadUrl(url);