loadUrl 后调用 loadData 时 Oreo WebView 背景颜色错误

Oreo WebView background color is wrong when calling loadData after loadUrl

将背景颜色设置为透明然后使用 loadUrl 时,一切正常。一旦调用 loadData,背景颜色就会变为白色。 当仅使用 loadData 而未使用 loadUrl 时,背景颜色也是正确的。

此行为仅在 Android Oreo 中观察到。

    LinearLayout ll = new LinearLayout(this);
    ll.setBackgroundColor(Integer.parseInt("55FF4081", 16));
    setContentView(ll);

    final WebView wv = new WebView(this);
    ll.addView(wv, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

    wv.setBackgroundColor(Color.TRANSPARENT);

    wv.loadUrl("https://slack.com");

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            wv.loadData("test", "text/html", "utf-8");
        }
    }, 6000);

这是 chromium 中的一个错误,已在版本 66 中修复。