Android webview custom error page

前端 未结 3 475
北荒
北荒 2021-02-05 12:41

I am creating application that use WebView to access a online website. I am stuck where I have to add code to check availability of page.

public class SpartanWeb         


        
3条回答
  •  情书的邮戳
    2021-02-05 13:07

    You can call loadErrorPage(view) function in the onReceivedError function.

    The following code will load the error content you need to show.Here i am load the html file with loadDataWithBaseURL.

    public void loadErrorPage(WebView webview){
            if(webview!=null){
    
                String htmlData ="
    "This is the description for the load fail : "+description+"\nThe failed url is : "+failingUrl+"\n"
    "; webview.loadUrl("about:blank"); webview.loadDataWithBaseURL(null,htmlData, "text/html", "UTF-8",null); webview.invalidate(); } }

提交回复
热议问题