我有一个应用程序,使大量使用的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");
}
});
上一篇:startActivityForResult从片段和整理的子活动(),不以片段叫onActivityResult()片段、不以、startActivityForResult、onActivityRes
下一篇:如何禁用"接下来"一个软件的EditText键盘上的按钮(带&QUOT更换;完成"按钮)按钮、接下来、键盘、软件