jax
jax

Reputation: 38583

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?

Upvotes: 2

Views: 11325

Answers (2)

diyism
diyism

Reputation: 12935

Currently, we could webview.setBackgroundColor(Color.TRANSPARENT) in onLayout(), and then add style="background-color:white" into html element.

Upvotes: 0

Senthil Mg
Senthil Mg

Reputation: 3313

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); 

Upvotes: 16

Related Questions