Chaitanya Karmarkar
Chaitanya Karmarkar

Reputation: 1595

I am using LinearProgressIndicator with WebView to show web page rendering progress, how to hide it when progress animation reaches 100?

I am using LinearProgressIndicator with WebView to show web page rendering progress. I am using onProgressChanged (WebView view,int newProgress) of WebChromeClient for that purpose like below:

            @Override
            public void onProgressChanged(WebView view, final int newProgress) {
                super.onProgressChanged(view, newProgress);
                   if (newProgress == 100) {
                   indicator.setProgressCompat(100,true);
                   //todo implement listener to hide progress indicator

                   } else {
                   indicator.setProgressCompat(newProgress,true);
                  }
                        
            }

Now consider this scenario: Progress indicator has current progress = 70 and newProgress which we have to set is 100. So, I want to hide progress indicator after its animation is finished. If I hide it using progressBar.hide(); after indicator.setProgressCompat(100,true); then it becomes hidden, but there is one issue, it quickly becomes hidden even if its animation which is changing its progress from 70 to 100 is currently running. I don't want this to happen, I want to hide progress indicator when its animation which is animating its progress from 70 to 100 is ended. Is there any listener to achieve this?

Upvotes: 1

Views: 380

Answers (1)

Lan Nguyen
Lan Nguyen

Reputation: 795

The simple way is just to delay your hide action after a specific time.

int delayTime = 2000;
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
      @Override
      public void run() {
        indicator.hide();
      }
    }, delayTime);

Test with your finest delayTime value.

Upvotes: 0

Related Questions