How to show ProgressBar like Google Play store when downloading an app

41 Views Asked by At

I try to show ProgressBar initially as Indeterminate mode before the server connection after connecting shows ProgressBar as Determinate mode. like Google Play Store in Android when an app is downloaded before download shows Progressbar as Indeterminate and when the download is started it shows progress. how to show like that I failed to show like in the image below.

Here is XML code

        <ProgressBar
            android:id="@+id/progress"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="@dimen/_12sdp"
            android:layout_gravity="center"
            android:layout_margin="@dimen/_8sdp"
            android:contentDescription="@string/todo"
            android:progressDrawable="@drawable/progress_bar_effect"
            android:visibility="invisible" />

Here is Java code

private void startDownload() { 
        progressBar.setIndeterminate(true); // Indeterminate mode for initial progress
        new Thread(new Runnable() {
            public void run() {
               // Set determinate mode for downloading progress
                while (progressStatus < 100) {
                     ... 
                    handler.post(new Runnable() {
                        public void run() {
                            progressBar.setProgress(progressStatus);
                        }
                    }); 
                     ...  
                }
            handler.post(new Runnable() {
                public void run() {
                    // Set Determinate mode and hide the progress bar
                    progressBar.setIndeterminate(false); 
                }
            });
        }
    }).start();
}

Indeterminate mode enter image description here

Determinate mode enter image description here

0

There are 0 best solutions below