Android show progress bar when webview load url

I am new in android apps development and learning it.

I have developed an application which load a website link using webview. And it’s working fine.

But i am facing problem to display and hide progress bar when webview load a page.

I want to display progress bar (Just spinner in center) when webview load main link and internal links of website and hide progress bar when page loaded completely.

My java codes are :

package in.matebook.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {

protected void onCreate(Bundle savedInstanceState) {
    WebView myWebView = (WebView) findViewById(;
    myWebView.setWebViewClient(new MyWebViewClient());
    WebSettings webSettings = myWebView.getSettings();

private class MyWebViewClient extends WebViewClient {

    public boolean shouldOverrideUrlLoading(WebView view, String url) {

        if (Uri.parse(url).getHost().equals("")) {
            // This is my web site, so do not override; let my WebView load the page
            //or we can add more allowed host in if condition
            return false;
        // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        return true;


public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(, menu);
    return false;

public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == {
        return true;

    return super.onOptionsItemSelected(item);

And my layout XML codes are :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""

<WebView  xmlns:android=""

    android:layout_centerHorizontal="true" />


Right now progress bar is displaying but do not hide.

When i create progressbar object and add below line in java code then progress bar do not display.


I have also try other answer in Stack Overflow like

Android. How can i show progress bar while loading data to webview?

But progress bar do not work when i click on internal links.

  1. I want to display progress bar when main page load and hide progress bar when main page loaded completely.

  2. i want to display progress bar again when user click on internal links of website and same as above hide progress bar when page loaded completely.

Please help i am beginner in android apps development.

Source: xml

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.