如何显示进度对话框,而HTML页面中的WebView加载对话框、进度、加载、页面

2023-09-06 03:22:51 作者:不是奇葩难闯天下

我使用的网络视图显示HTML网页,我想显示一个进度对话框,直到页面加载。当做到这一点,该对话框具有消失。我已经使用的AsyncTask这一点,但该对话框不会显示。请看下文中我code:

I am using the web view for showing html pages, and I want to show a progress dialog until the page is loaded. When that is done, the dialog has to disappear. I have used AsyncTask for this, but the dialog doesn't show. See my code below:

 class DownloadAysnc extends AsyncTask<String, String, Void>
   {
    ProgressDialog progressDialog;
        @Override
          protected void onPreExecute() {
          super.onPreExecute();
          progressDialog = ProgressDialog.show(OverView.this, "", "Please Wait ...");
        }

        @Override
          protected Void doInBackground(String... arg0) {
          webView.loadUrl("http://marico.com/html/investor/overview.php");
        return null;
       }

        @Override
          protected void onPostExecute(Void result){
          super.onPostExecute(result);
          progressDialog.dismiss();
       }
   }

如果我把谷歌文档的帮助下,显示的网页,然后将HTML标记显示,而不是页面。下面是code:

And if I take the help of google docs to show the web page, then the HTML Tag is shown, but not the page. Below is that code:

String url = "http://google.co.in/";
String googleDocsUrl = "http://docs.google.com/viewer?url="+url;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(googleDocsUrl ), "text/html");
startActivity(intent);

this.myWebView.loadUrl(googleDocsUrl);  

有人可以帮助我?

Can someone help me with this?

推荐答案

使用这种code:

webView.setWebViewClient(new WebViewClient() {
    ProgressDialog prDialog;
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        prDialog = ProgressDialog.show(Activity.this, null, "loading, please wait...");
        super.onPageStarted(view, url, favicon);
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        prDialog.dismiss();
        super.onPageFinished(view, url);
    }
});

webView.loadUrl(url);