在Webview中处理网络问题 [英] Handle network issues in webview

查看:270
本文介绍了在Webview中处理网络问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Google文档中的文档加载到我的Web视图中.我看到的问题是,当用户启动应用程序且未连接到网络时,会看到以下屏幕:

I am loading a document from google docs into my webview. The problem I see is that when user launch the app and is not connected to network, sees the following screen:

现在,如果他连接到网络,在不重新启动应用程序的情况下,如何在webview中打开该链接.单击webview中的链接是一个选项,但是如果发生这种情况,我是否可以提供一种更好的用户友好方式来重新加载webview中的页面?

Now if he connects to the network, what is the way to open that link inside webview without re-launching the app. Clicking that link in the webview is one option but can I provide some better user friendly way to reload page in webview if this kind of scenario happens?

推荐答案

您可以在WebViewClient中捕获网络错误,并显示自己定制的布局,如下所示:

You can catch network error in WebViewClient, and show layout which custom by youself, like this:

       webView.setWebViewClient(new WebViewClient() {

            @Override
            public void onReceivedError(final WebView view, int errorCode, String description,
                    final String failingUrl) {
                //control you layout, show something like a retry button, and 
                //call view.loadUrl(failingUrl) to reload.
                super.onReceivedError(view, errorCode, description, failingUrl);
            }
        });

这篇关于在Webview中处理网络问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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