1

无法webPage not available在 Web 视图中清除消息。

book.clearView()onReceivedError方法中没有清除,当加载失败时WebView仍然显示,任何帮助将不胜感激。webPage not available messageWebView

final WebView book = (WebView)findViewById(R.id.book);
        //book.setBackgroundColor(Color.parseColor("#123456"));
        book.setBackgroundColor(0);
        book.setBackgroundResource(R.drawable.pnr)
              WebSettings settings = book.getSettings();
                    settings.setJavaScriptEnabled(true);
                    book.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

                    final AlertDialog alertDialog = new AlertDialog.Builder(this).create();

                   final ProgressDialog dialog =ProgressDialog.show(AboutApp.this,null, "Loading...");

                    book.setWebViewClient(new WebViewClient(){

                        @Override
                        public void onPageStarted(WebView view, String url, Bitmap favicon) {
                            // TODO Auto-generated method stub
                            //dialog = ProgressDialog.show(AboutApp.this,null, "Loading...");

                            super.onPageStarted(view, url, favicon);

                        }

                        @Override
                        public void onPageFinished(WebView view, String url) {
                            // TODO Auto-generated method stub
                            if(dialog.isShowing()){
                                dialog.dismiss();
                            }
                            super.onPageFinished(view, url);
                        }

                        @Override
                        public boolean shouldOverrideUrlLoading(WebView view, String url) {
                            // TODO Auto-generated method stub
                            //Log.i(TAG, "Processing webview url click...");
                            view.loadUrl(url);
                            return true;

                        }

                         public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                            // Log.e(TAG, "Error: " + description);
                             //Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
                             book.clearView();
                             alertDialog.setTitle("Error");
                             alertDialog.setMessage("Sorry, This particular service is unavailable at this time.Please try again later");
                             alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                                 public void onClick(DialogInterface dialog, int which) {
                                     finish();
                                     return;
                                 }
                             });
                             alertDialog.show();
                         }

                    });

                    book.loadUrl("www.google.com");
4

1 回答 1

2

我们需要设计自己的 html 文件,将该文件放在 assests 文件夹下,然后使用 loadUrl() 方法加载 html 文件。例如:book.loadUrl("file:///android_asset/error.html");

于 2012-08-18T20:29:20.907 回答