处理webview中的网络问题

San*_*eep 6 android webview

我正在将谷歌文档中的文档加载到我的webview中.我看到的问题是,当用户启动应用程序但未连接到网络时,请看以下屏幕:

在此输入图像描述

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

小智 10

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

       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);
            }
        });
Run Code Online (Sandbox Code Playgroud)