How do i make my progress dialog dismiss after webview is loaded?

后端 未结 6 1478
一向
一向 2020-12-10 17:22

What do I need to my code to make the dialog dismiss() after the webview is loaded?

public void onCreate(Bundle savedInstanceState) { 
                  


        
6条回答
  •  忘掉有多难
    2020-12-10 18:13

    If you simply want to show Progress before webPage loading in WebView. You can simply request for Window Feature Progress like

    getWindow().requestFeature(Window.FEATURE_PROGRESS); 
    

    before setContentView(R.layout.blahblah);

    and show it progress in onProgressChanged like

     final Activity context= this;
     webview.setWebChromeClient(new WebChromeClient() 
     {
       public void onProgressChanged(WebView webView, int progress) 
       {
         activity.setProgress(progress * 1000);
       }
     });
    

    And if you want to add you own ProgressDialog then use WebviewClient

    webView.setWebViewClient(new WebViewClient() {
        ProgressDialog rogressDialog ;
        @Override
        public void onPageStarted(WebView view, String url, Bitmap bitmap) {
            progressDialog = ProgressDialog.show(context, "Loading...", "Please wait...");//where context = YourActivity.this;
            super.onPageStarted(view, url, bitmap);
        }
    
        @Override
        public void onPageFinished(WebView view, String url) {
            progressDialog .dismiss();
            super.onPageFinished(view, url);
        }
    });
    
    webView.loadUrl(url);
    

提交回复
热议问题