Types of Progress Bars and Change Color of progress bar in Android

Types of Progress bar's in Android example

In this tutorial we will learn to implement progress bar and change the color of progress bar with an example in Android.

Progress Bar is used to show the user loading of some content or to download some content in Android Applications.

Example:
  • Create a new project in Android Studio and name it as ProgressBars.
  • Design the main layout as follows.
File: activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.hss_24.progressbars.MainActivity">


    <TextView
        android:text="ANDROID LOVERS"
        android:textStyle="bold"
        android:textSize="28sp"
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:text="Types of Progress Bar's"
        android:gravity="center"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <ProgressBar
        android:id="@+id/progress_one"
        android:layout_marginTop="20dp"
        style="?android:attr/progressBarStyleSmall"
        android:indeterminate="true"
        android:indeterminateTintMode="src_atop"
        android:indeterminateTint="@color/colorAccent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <ProgressBar
        android:id="@+id/progress_two"
        android:layout_marginTop="20dp"
        android:indeterminate="true"
        android:indeterminateTintMode="src_atop"
        android:indeterminateTint="@color/colorAccent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <ProgressBar
        android:id="@+id/progress_three"
        android:layout_marginTop="40dp"
        android:indeterminate="true"
        android:indeterminateTintMode="src_atop"
        android:indeterminateTint="@color/colorAccent"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <ProgressBar
        android:id="@+id/progress_four"
        android:layout_marginTop="60dp"
        android:indeterminate="true"
        android:indeterminateTintMode="src_atop"
        android:indeterminateTint="@color/colorAccent"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />


</LinearLayout>
  • Design the main layout as follows.
  • No need to code anything just run the Application.
File: MainActivity.java:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}
  • Run the Application and enjoy the progress bars.
Output:








Download Project



Thank You!!!
Please like and share...

Comments