如何显示进度对话框,而HTML页面中的WebView加载 [英] How to show a progress dialog while HTML page is loaded in WebView

查看:117
本文介绍了如何显示进度对话框,而HTML页面中的WebView加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的网络视图显示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);

这篇关于如何显示进度对话框,而HTML页面中的WebView加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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