title: How to add a progress/loading bar in WebView
body: <p>I developed a website for my entreprisee and I work almost exclusively with PHP</p>
  
  <p>So the Java language (and android studio) is a really new for me</p>
  
  <p>Despite this I have to create an APK to use the website (in order to block the android home on this site)</p>
  
  <p>For the moment I managed to set up refresh pages, and now I am trying to add a progress/loading bar to my application that uses WebView but it doesn't work ..</p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>import android.support.v4.widget.SwipeRefreshLayout;
  import android.app.Activity;
  import android.os.Bundle;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  
  public class MainActivity extends Activity {
  
      WebView webView;
  
      SwipeRefreshLayout swipe;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          swipe = (SwipeRefreshLayout) findViewById(R.id.swipe);
          swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
              @Override
              public void onRefresh() {
                  webView.reload();
              }
          });
  
          LoadWeb();
  
      }
  
  
      public void LoadWeb(){
  
          webView = (WebView) findViewById(R.id.webView);
          webView.getSettings().setJavaScriptEnabled(true);
          webView.getSettings().setAppCacheEnabled(true);
          webView.loadUrl("https://www.google.com/");
          swipe.setRefreshing(true);
          webView.setWebViewClient(new WebViewClient(){
  
              public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
  
                  webView.loadUrl("file:///android_asset/error.html");
              }
  
              public  void onLoadResource(WebView view, String url) { //Doesn't work
                  swipe.setRefreshing(true);
              }
  
              public  void  onPageFinished(WebView view, String url){
  
                  //Hide the SwipeReefreshLayout
  
                  swipe.setRefreshing(false);
              }
  
          });
      }
  
      @Override
      public void onBackPressed(){
  
          if (webView.canGoBack()){
              webView.goBack();
          }else {
              finish();
          }
      }
  }
  </code></pre>
  
  <p><strong>Activity_main.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="eu.test.testappli.MainActivity"&gt;
  
      &lt;android.support.v4.widget.SwipeRefreshLayout
          android:id="@+id/swipe"
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
  
          &lt;WebView
              android:id="@+id/webView"
              android:layout_width="match_parent"
              android:layout_height="match_parent"/&gt;
  
      &lt;/android.support.v4.widget.SwipeRefreshLayout&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>It may seem simple, but the java remains obscure for me so I can not implement the pieces of code that I find on the web ..</p>