How to show a progress dialog while HTML page is loaded in WebView

浪尽此生 提交于 2019-12-04 07:32:41

Use 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);
  v.setWebChromeClient(new WebChromeClient(){
      @Override
      public void onProgressChanged(WebView view, int newProgress) {
          WebView v=(WebView)findViewById(R.id.wv);
          //Toast.makeText(mContext, v.getUrl() + newProgress +"uploading...", Toast.LENGTH_SHORT).show();
          ProgressBar s=(ProgressBar)findViewById(R.id.progressBar1);
          s.setMax(100);
          s.setProgress(newProgress);
          if(newProgress==100){                        
              v.setVisibility(0);
              //Toast.makeText(mContext, "upload finished...", Toast.LENGTH_SHORT).show();
         }else{
              v.setVisibility(8);
              //Toast.makeText(mContext, "uploading...", Toast.LENGTH_SHORT).show();
          }
        }
    });

You can show the Progress of the WebView in the Title Bar of the WebView. Here is a complete example for the same that show Progress Status in the Title Bar of the WebView.

You can try following code,

progDailog = ProgressDialog.show(loginAct,"Process ", "please wait....",true,true);

new Thread ( new Runnable()
{
     public void run()
     {
      // your code goes here
     }
}).start();

 Handler progressHandler = new Handler() 
 {

     public void handleMessage(Message msg1) 
     {
         progDailog.dismiss();
     }
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!