title: Android webview loading dialog
body: <p>I'm trying to implement a loading dialog in my webview application but whatever I do it just won't work.</p>
  
  <p>What I want is the following, everytime someone clicks a link in the webview the loading dialog has to popup like this: </p>
  
  <p><a href="https://i.stack.imgur.com/d1xSn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/d1xSn.png" alt="loading dialog"></a><br>
  <sub>(source: <a href="https://thedevelopersinfo.files.wordpress.com/2009/10/without_title4.png?w=600" rel="nofollow noreferrer">wordpress.com</a>)</sub>  </p>
  
  <p>And when the loading is done it has to disappear. Can anyone show me how to do it in my own source? I've tried a lot of things but there's always an issue so I really don't know how to.</p>
  
  <p>This is my WebviewActivity:</p>
  
  <pre><code>import android.content.res.Configuration;
  import android.os.Bundle;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.Window;
  import android.webkit.WebSettings;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  
  public class WebviewActivity extends MainActivity {
  
      private WebView myWebView;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          this.requestWindowFeature(Window.FEATURE_NO_TITLE);
          setContentView(R.layout.main);
  
          myWebView = (WebView)findViewById(R.id.webview);        
          WebSettings webSettings = myWebView.getSettings();
          webSettings.setJavaScriptEnabled(true);        
          myWebView.setWebViewClient(new WebViewClient());
  
          myWebView.requestFocus(View.FOCUS_DOWN);
          myWebView.setOnTouchListener(new View.OnTouchListener() {
              public boolean onTouch(View v, MotionEvent event) {
                  switch (event.getAction()) {
                      case MotionEvent.ACTION_DOWN:
                      case MotionEvent.ACTION_UP:
                          if (!v.hasFocus()) {
                              v.requestFocus();
                          }
                          break;
                  }
                  return false;
              }
          });
      }   
  
      @Override
      public void onResume() {
          super.onResume();
          if ( isOnline() == true )
              myWebView.loadUrl(webLink);
          else if ( isOnline() == false )
              showNoConnectionDialog();
      }
  
      @Override
      public void onConfigurationChanged(Configuration newConfig){        
          super.onConfigurationChanged(newConfig);
      }
  }
  </code></pre>
  
  <p>Thank you very much for your help!!</p>