title: Show Progress using ProgressBar for WebViewClient
body: <p>I am using WebViewClient to load web pages and I would like to show progress bar for my code. My code isn't loading the progress gradually. It only shows 100% progress. How do I set the progress based on web page loading time? </p>
  
  <p>For my purpose I have to load just "<a href="https://www.google.com" rel="nofollow noreferrer">https://www.google.com</a>" on a WebView only. Please help. Thank you. Code is shown below :</p>
  
  <p>Activity file</p>
  
  <pre><code>public class MainActivity extends Activity {
  
  private WebView webView;
  private ProgressBar progressBar;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      int vc = Color.parseColor("#feca01");
  
  
      progressBar = (ProgressBar) findViewById(R.id.determinateBar);
      progressBar.getProgressDrawable().setColorFilter(
              vc, android.graphics.PorterDuff.Mode.SRC_IN);
      webView = (WebView) findViewById(R.id.webView);
      webView.setWebViewClient(new MyBrowser());
      webView.getSettings().setJavaScriptEnabled(true);
      webView.loadUrl("http://deelay.me/5000/http://www.google.com");
  
  }
  
  private class MyBrowser extends WebViewClient {
  
      @Override
      public void onPageStarted(WebView view, String url, Bitmap favicon)
      {
          super.onPageStarted(view, url, favicon);
          progressBar.setVisibility(View.VISIBLE);
          progressBar.incrementProgressBy(10);
  
      }
  
      @Override
      public boolean shouldOverrideUrlLoading(WebView view, String url) {
          view.loadUrl(url);
          return true;
      }
  
      @Override
      public void onPageFinished(WebView view, String url) {
          super.onPageFinished(view, url);
          progressBar.setVisibility(View.VISIBLE);
         // progressBar.setProgress(0);
      }
   }
  </code></pre>
  
  <p>}</p>
  
  <p>XML file</p>
  
  <p>`</p>
  
  <p></p>
  
  <pre><code>&lt;ProgressBar
      android:id="@+id/determinateBar"
      style="@android:style/Widget.ProgressBar.Horizontal"
      android:layout_width="400dp"
      android:padding="0dp"
      android:layout_height="2dp" /&gt;
  
  &lt;WebView
      android:layout_height="match_parent"
      android:id="@+id/webView"
      android:layout_weight="0.91"
      android:layout_width="match_parent"
      android:padding="0dp"
      /&gt;
  </code></pre>
  
  <p>`</p>