android webview rendering is showing a White Page

前端 未结 3 1677
天命终不由人
天命终不由人 2021-02-04 22:31

Sometimes, when I load my webview with loadUrl, the website is not showing up until I touch the screen or scroll.

It\'s like I have a webview drawing problem.

         


        
相关标签:
3条回答
  • 2021-02-04 22:44

    I'am not sure, I don't have the whole code, but I think is related to the webViewClient implemented in this function:

    public boolean shouldOverrideUrlLoading(WebView view, String url){
        // do your handling codes here, which url is the requested url
        // probably you need to open that url rather than redirect:
        view.loadUrl(url);
        view.setVisibility(View.VISIBLE);
        return false; // then it is not handled by default action
    }
    

    here is the officiel definition:

    public boolean shouldOverrideUrlLoading (WebView view, String url)

    Try to test with your code without implementing shouldOverrideUrlLoading, or make it return true.

    0 讨论(0)
  • 2021-02-04 22:47

    What version of Android are you testing on? Pre-4.1 versions of Android seem to have this sort problem with WebViews sometimes.

    Add this to the manifest for that Activity to fix the problem:

    android:hardwareAccelerated="false"
    
    0 讨论(0)
  • 2021-02-04 22:55

    Make WebView invisible in your layout:

    <WebView
        ...
        android:visibility="invisible"
        .../>
    

    Now, show it back when onPageFinished occurs for the fist time:

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            if (webView.getVisibility() != View.VISIBLE) {
                webView.setVisibility(View.VISIBLE);
            }
        }
    });
    
    0 讨论(0)
提交回复
热议问题