How to add progress bar in android studio

How to add progress bar in android studio

 

 

 

code 1

 

private ProgressBar progressBar;

private int progressStatus = 0;

private TextView textView;

private Handler handler = new Handler();

 

 

 

—————–

 

code 2

 

 

progressBar = (ProgressBar) findViewById(R.id.progressBar);

textView = (TextView) findViewById(R.id.textView);

// Start long running operation in a background thread

new Thread(new Runnable() {

public void run() {

while (progressStatus < 100) {

progressStatus += 1;

// Update the progress bar and display the

//current value in the text view

handler.post(new Runnable() {

public void run() {

progressBar.setProgress(progressStatus);

textView.setText(progressStatus+”/”+progressBar.getMax());

}

});

try {

// Sleep for 200 milliseconds.

Thread.sleep(200);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

}).start();

 

 

 

 

 

 

 

 

 

 

—————

 

 

 

 

 

 

 

 

code 3

 

 

 

<ProgressBar

 

android:id=”@+id/progressBar”

style=”?android:attr/progressBarStyleHorizontal”

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:layout_alignParentLeft=”true”

android:layout_alignParentTop=”true”

android:layout_marginLeft=”23dp”

android:layout_marginTop=”20dp”

android:indeterminate=”false”

android:max=”100″

android:minHeight=”50dp”

android:minWidth=”200dp”

android:progress=”1″ />

 

<ProgressBar

android:id=”@+id/progressBar_cyclic”

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:minHeight=”50dp”

android:minWidth=”50dp”

android:layout_centerVertical=”true”

android:layout_centerHorizontal=”true” />

 

<TextView

android:id=”@+id/textView”

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:layout_alignLeft=”@+id/progressBar”

android:layout_below=”@+id/progressBar”/>

 

 

<TextView

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:text=”Hello World!”

app:layout_constraintBottom_toBottomOf=”parent”

app:layout_constraintLeft_toLeftOf=”parent”

app:layout_constraintRight_toRightOf=”parent”

app:layout_constraintTop_toTopOf=”parent” />

Leave a Comment