How to create a circular progress bar in Android

In this android programming source code example, we are going to create a circular progress bar in android.

You can copy and adopt this source code example to your android project without reinventing the wheel.

Below is a step by step source code to create a circular progress bar in android.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    tools:context=".progressbar.ProgressBar2">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Circular ProgressBar "/>

    <com.mikhaellopez.circularprogressbar.CircularProgressBar
        android:layout_margin="30dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:cpb_background_progressbar_color="#FFCDD2"
        app:cpb_background_progressbar_width="5dp"
        app:cpb_progressbar_color="#F44336"
        app:cpb_progressbar_width="10dp" />

</LinearLayout>

MainActivity.java

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.inducesmile.inducesmile_button.R;

public class ProgressBar2 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progress_bar2);
    }
}

build.gradle

implementation 'com.mikhaellopez:circularprogressbar:2.0.0'

If you have any question or suggestions kindly use the comment box or you can contact us directly through our contact page below.

 

Add a Comment