Android WebView renders blank/white, view doesn't update on css changes or HTML changes, animations are choppy

后端 未结 9 1494
不知归路
不知归路 2020-11-27 10:25

When ever I make a css class change, the changes don\'t always appear. This appears to happen when I have a touch event that adds something like a down class name to a butto

9条回答
  •  -上瘾入骨i
    2020-11-27 10:46

    As pointed out above and elsewhere - overriding View.onDraw() and calling View.invalidate will make for an unhappy battery / app performance will drop. You can also do a manual invalidate call ever x ms like so

    /**
     * Due to bug in 4.2.2 sometimes the webView will not draw its contents after the data has loaded. 
     * Triggers redraw. Does not work in webView's onPageFinished callback for some reason
     */
    private void forceWebViewRedraw()
    {
        mWebView.post(new Runnable() {
            @Override
            public void run()
            {
                mWebView.invalidate();
                if(!isFinishing())
                    mWebView.postDelayed(this, 1000);
            }
        });
    }
    

    I tried putting an invalidate call in WebViewClient.onPageLoaded() but this does not seem to work. While my solution could be better its simple and it works for me (im just showing a twitter login)

提交回复
热议问题