Android Studio - Different types of Progress Bars
activity_main.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="@+id/textView17"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="\u00A9 itinsidenews.com"
android:textAlignment="center"
android:textSize="18sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Determinate" />
<ProgressBar
android:id="@+id/progressDeterminate"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="false"
android:max="100"
android:progress="10" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Indeterminate" />
<ProgressBar
android:id="@+id/progressIndeterminate"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Buffer" />
<ProgressBar
android:id="@+id/progressBuffered"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="false"
android:max="100"
android:progress="10"
android:secondaryProgress="20" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Indeterminate and Determinate" />
<ProgressBar
android:id="@+id/progressIndeterminateDeterminate"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="false"
android:max="100"
android:progress="20" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Indeterminate" />
<ProgressBar
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:progressDrawable="@drawable/circular_progress_bar" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="Determine" />
<ProgressBar
android:id="@+id/progressIndeterminateCircular"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/circle_shape"
android:indeterminate="false"
android:max="100"
android:progress="0"
android:progressDrawable="@drawable/circular_progress_bar" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
MainActivity.java
package com.progressbar.example.mainactivity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ProgressBar;
import androidx.appcompat.app.AppCompatActivity;
import com.progressbar.example.R;
public class MainActivity extends AppCompatActivity {
private ProgressBar progressDeterminate;
private ProgressBar progressIndeterminateCircular;
private ProgressBar progressBuffered;
private ProgressBar progressIndeterminateDeterminate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initComponent();
}
private void initComponent() {
progressDeterminate = (ProgressBar) findViewById(R.id.progressDeterminate);
progressIndeterminateCircular = (ProgressBar) findViewById(R.id.progressIndeterminateCircular);
progressBuffered = (ProgressBar) findViewById(R.id.progressBuffered);
progressIndeterminateDeterminate = (ProgressBar) findViewById(R.id.progressIndeterminateDeterminate);
startDeterminateProgress();
startBufferedProgress();
startBufferedSecondaryProgress();
startIndeterminateDeterminateProgress();
startDeterminateCircularProgress();
}
private void startDeterminateProgress() {
final Handler mHandler = new Handler();
Runnable runnable = new Runnable() {
public void run() {
int progress = progressDeterminate.getProgress() + 10;
progressDeterminate.setProgress(progress);
if (progress > 100) {
progressDeterminate.setProgress(0);
}
mHandler.postDelayed(this, 1000);
}
};
mHandler.post(runnable);
}
private void startBufferedProgress() {
final Handler mHandler = new Handler();
Runnable runnable = new Runnable() {
public void run() {
int progress = progressBuffered.getProgress() + 5;
progressBuffered.setProgress(progress);
if (progress > 100) {
progressBuffered.setProgress(0);
}
mHandler.postDelayed(this, 500);
}
};
mHandler.postDelayed(runnable, 500);
}
private void startBufferedSecondaryProgress() {
final Handler mHandler = new Handler();
Runnable runnable = new Runnable() {
public void run() {
int progress = progressBuffered.getSecondaryProgress() + 5;
progressBuffered.setSecondaryProgress(progress);
if (progress > 100 && progress_buffered.getProgress() <= 10) {
progressBuffered.setSecondaryProgress(0);
}
mHandler.postDelayed(this, 250);
}
};
mHandler.post(runnable);
}
private void startIndeterminateDeterminateProgress() {
final Handler mHandler = new Handler();
Runnable runnable = new Runnable() {
public void run() {
if (progressIndeterminateDeterminate.isIndeterminate()) {
progressIndeterminateDeterminate.setIndeterminate(false);
mHandler.postDelayed(this, 1000);
} else {
int progress = progressIndeterminateDeterminate.getProgress() + 20;
progressIndeterminateDeterminate.setProgress(progress);
if (progress > 100) {
progress_indeterminate_determinate.setProgress(0);
progressIndeterminateDeterminate.setIndeterminate(true);
mHandler.postDelayed(this, 4000);
} else {
mHandler.postDelayed(this, 1000);
}
}
}
};
mHandler.post(runnable);
}
private void startDeterminateCircularProgress() {
final Handler mHandler = new Handler();
Runnable runnable = new Runnable() {
public void run() {
int progress = progressIndeterminateCircular.getProgress() + 10;
progressIndeterminateCircular.setProgress(progress);
if (progress > 100) {
progressIndeterminateCircular.setProgress(0);
}
mHandler.postDelayed(this, 1000);
}
};
mHandler.post(runnable);
}
}
Output
![](https://learnoset.com/Learnoset/CodeOutput/1617701217951.gif)
Projects with Source Code + Video Tutorials
You can download our Java and Android Studio Projects with Source Code and Video Tutorials.
![Simple-Music-Player-App-(Version-2)-for-Android-(Offline-Version)](https://learnoset.com/Learnoset/Projects/MusicPlayer2/music_player2.png)
Simple Music Player App (Version 2) for Android (Offline Version)
![Firebase-Push-Notifications-|-Background-Notification](https://learnoset.com/Learnoset/Projects/FirebasePushNoti/firebase_push_notification.png)
Firebase Push Notifications | Background Notification
![Programming-Quiz-App-for-Android-(Offline-Version)](https://learnoset.com/Learnoset/Projects/OflineQuiz/thumnail.jpg)
Programming Quiz App for Android (Offline Version)
If you have any Questions or Queries
You can mail us at info.learnoset@gmail.com
Follow us to learn Coding and get in touch with new Technologies.