Webview中的setBackgroundColor()无法正常工作

jax*_*jax 2 android android-webview

我创建了一个透明背景的webview.

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);
Run Code Online (Sandbox Code Playgroud)

这是JavaInterface,当提交html表单并且所有复选框都通过测试时,它应该改变背景的颜色.

/**
 * 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;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,这不起作用,并且返回的文档仍然具有透明背景.我做错了什么,似乎browser.setBackgroundColor(Color.WHITE);什么都不做?

Sen*_* Mg 16

你可以webviewsetbackgroundResource方法覆盖背景,

试试这样你会得到它,

wv.setBackgroundColor(0);
wv.setBackgroundResource(color.blue);
wv.loadUrl(url); 
Run Code Online (Sandbox Code Playgroud)