0

I want progress bar when website loading in the webview.

I searched for solution not satisfied.

Please anyone help me?

When I click any link in webpage it loads perfectly but I want to know how much it loaded. So, I need progress bar in top of webview while loading

Bala Raja
  • 627
  • 6
  • 20

3 Answers3

0

Create a progress view, and when the webview is loading (using onProgressChanged), set the current progress, and when finished, hide it.

It is so easy and there are solutions over there for that.

Edit: IMO this is a duplicate of Android WebView progress bar

Community
  • 1
  • 1
xdevs23
  • 3,824
  • 3
  • 20
  • 33
0

Here is example code how you can use webview client for this i have used gif imageview you can use progressbar instead it.

public class myWebClient extends WebViewClient {
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {

        super.onPageStarted(view, url, favicon);
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {

        ivGif.setBackgroundResource(R.drawable.anim_set_frames);
        AnimationDrawable progressAnimation = (AnimationDrawable) ivGif.getBackground();
        progressAnimation.start();
        ivGif.setVisibility(View.VISIBLE);
        view.loadUrl(url);
        return true;

    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        ivGif.setVisibility(View.GONE);
    }
}




    webViewBooking.setWebViewClient(new myWebClient());
    webViewBooking.getSettings().setJavaScriptEnabled(true);
    webViewBooking.loadUrl(payment_url);
Ajay Pandya
  • 2,417
  • 4
  • 29
  • 65
-1

Simple way is like this;

     public class MyActivity extends Activity {
     private static final int PROGRESS = 0x1;

     private ProgressBar mProgress;
     private int mProgressStatus = 0;

     private Handler mHandler = new Handler();

     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);

         setContentView(R.layout.progressbar_activity);

         mProgress = (ProgressBar) findViewById(R.id.progress_bar);

         // Start lengthy operation in a background thread
         new Thread(new Runnable() {
             public void run() {
                 while (mProgressStatus < 100) {
                     mProgressStatus = doWork();

                     // Update the progress bar
                     mHandler.post(new Runnable() {
                         public void run() {
                             mProgress.setProgress(mProgressStatus);
                         }
                     });
                 }
             }
         }).start();
     }
 }