找不到网页"从显示&QUOT prevent的WebView; [英] Prevent WebView from displaying "web page not available"

查看:260
本文介绍了找不到网页"从显示&QUOT prevent的WebView;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,使大量使用的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();
 }
}

我发现了<一href="http://developer.android.com/reference/android/webkit/WebView.html#clearView%28%29">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");

    }
});

这篇关于找不到网页&QUOT;从显示&QUOT prevent的WebView;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆