How to add Progress Dailog and Progressbar in WebView android ?.

Progress Dialog :

I have added few lines in my previes Webview code and now its working fine with progress dialog.

 Progress Dialog could be a modal dialog, that prevents the user from interacting with the app. rather than exploitation this category, you ought to use a progress indicator like ProgressBar, which may be embedded in your app's UI. or else, you'll use a notification to tell the user of the task's progress.

A dialog showing a progress indicator associated an optional  text message or read. solely a text message or a read will be used at an equivalent time.

The dialog will be created cancelable on back key press.


The progress vary is zero to grievous bodily harm.

 final ProgressDialog pd = ProgressDialog.show(getActivity(),"","Please wait..");  
       webView.getSettings().setJavaScriptEnabled(true); // enable javascript  
       webView.getSettings().setLoadWithOverviewMode(true);  
       webView.getSettings().setUseWideViewPort(true);  
       webView.getSettings().setBuiltInZoomControls(true);  
       webView.setHorizontalScrollBarEnabled(false);  
       webView.setWebViewClient(new WebViewClient()  
       {  
         @Override  
         public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {  
           super.onReceivedError(view, request, error);  
         }  
         @Override  
         public void onPageStarted(WebView view, String url, Bitmap favicon) {  
           super.onPageStarted(view, url, favicon);  
           pd.show();  
         }  
         @Override  
         public void onPageFinished(WebView view, String url) {  
           super.onPageFinished(view, url);  
           pd.dismiss();  
         }  
       });  
       webView.loadUrl("https://java2android1108.blogspot.in/");  

ProgressBar:
A computer programme component that indicates the progress of associate degree operation. Progress bar supports 2 modes to represent progress: determinate, and indeterminate. For a visible summary of the distinction between determinate and indeterminate progress modes, see Progress & activity. show progress bars to a user in an exceedingly non-interruptive manner. Show the progress bar in your app's computer programme or in an exceedingly notification rather than inside a dialog.

Indeterminate Progress

Use indeterminate mode for the progress bar after you don't skills long associate degree operation can take. Indeterminate mode is that the default for progress bar and shows a cyclic animation while not a particular quantity of progress indicated. the subsequent example shows associate degree indeterminate progress bar

 <ProgressBar
      android:id="@+id/progressBar"      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      />



  getWindow().requestFeature(Window.FEATURE_PROGRESS);  
     setContentView(R.layout.main );  
     // Makes Progress bar Visible  
     getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);  
     webview = (WebView) findViewById(R.id.webview);  
     webview.setWebChromeClient(new WebChromeClient() {  
       public void onProgressChanged(WebView view, int progress)    
       {  
         //Make the bar disappear after URL is loaded, and changes string to Loading...  
         setTitle("Loading...");  
         setProgress(progress * 100); //Make the bar disappear after URL is loaded  
         // Return the app name after finish loading  
         if(progress == 100)  
           setTitle(R.string.app_name);  
         }  
       });  
     webview.setWebViewClient(new HelloWebViewClient());  
     webview.getSettings().setJavaScriptEnabled(true);  
     webview.loadUrl("https://java2android1108.blogspot.in/");  






Comments