找不到网页"从显示&QUOT prevent的WebView;找不到、网页、QUOT、prevent

2023-09-12 04:00:27 作者:Leave 离开

我有一个应用程序,使大量使用的WebView的。当这个应用程序的用户不具有Internet连接,一个网页说:找不到网页,并出现各种其他文字。有没有办法不显示在我的WebView这个通用的文字?我想提供自己的错误处理。

I have an app that makes extensive use of a WebView. When the user of this app does not have Internet connection, a page saying "web page not available" and various other text appears. Is there a way to not show this generic text in my WebView? I would like to provide my own error handling.

private final Activity activity = this;

private class MyWebViewClient extends WebViewClient
 public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
  // I need to do something like this:
  activity.webView.wipeOutThePage();
  activity.myCustomErrorHandling();
  Toast.makeText(activity, description, Toast.LENGTH_LONG).show();
 }
}

我发现了WebView->clearView实际上不清除图。

推荐答案

首先在HTML中创建自己的错误页面,并把它放在你的资产的文件夹,让我们称之为myerrorpage.html 然后用onReceivedError:

First create your own error page in HTML and put it in your assets folder, Let's call it myerrorpage.html Then with onReceivedError:

mWebView.setWebViewClient(new WebViewClient() {
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        mWebView.loadUrl("file:///android_asset/myerrorpage.html");

    }
});