Android WebView 在内部打开链接,捕获错误

webView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;//ture为在webview中打开
    }
   
});


webView.setWebChromeClient(new WebChromeClient() {
    @Override
    public void onReceivedTitle(WebView view, String title) {
        super.onReceivedTitle(view, title);
        if (title.contains("404") || title.contains("500") || title.contains("Error")) {
            //view.loadUrl("about:blank");// 避免出现默认的错误界面
            view.loadDataWithBaseURL(null, "^_^暂无内容", "text/html", "UTF-8", null);

        }
    }

});

 

你可能感兴趣的:(android开发)