无法在android中加载网页时隐藏“WebPage Not available”消息

时间:2012-08-18 19:36:45

标签: android webview

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

book.clearView()方法中的{p> onReceivedError未清除WebView,但加载webPage not available message失败时仍会显示WebView,我们将不胜感激任何帮助

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");

1 个答案:

答案 0 :(得分:2)

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