Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

How to Change the ProgressBar Color in Android?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

In this article, we will see how we can add color to a ProgressBar in android. Android ProgressBar is a user interface control that indicates the progress of an operation. For example, downloading a file, uploading a file on the internet we can see the ProgressBar estimate the time remaining in operation. Note in this article we will be using Java and XML to set the color.

Step by Step Implementation

Step 1: Create a New Project

Step 2: Create a custom ProgressBar

  • Go to the app > res > drawable > right-click > New > Drawable Resource File and name the file as progress_bg.
  • Inside the XML file add a rotate tag with some attributes(see code)
  • Inside rotate tag create a shape tag within which create the size and gradient tag
  • Attributes of these tags are given in the code below. 
  • Below is the code for the progress_bg.xml file. 


<?xml version="1.0" encoding="utf-8"?>
<!--use rotate tag to rotate the drawable-->
    <!--shape tag is used to 
        build a shape in XML-->
        <!--set the size of the shape-->
            android:height="76dip" />
        <!--set the color gradients
            of the shape-->
            android:useLevel="false" />

Step 3: Working with the activity_main.xml file

  • Go to the activity_main.xml file and refer to the following code. 
  • Open the activity_main.xml file and in the ProgressBar tag and set the drawable in indeterminateDrawable attribute. 
  • Below is the code for the activity_main.xml file.


<?xml version="1.0" encoding="utf-8"?>
    <!--set the custom progress bar here in
        the indeterminateDrawable attribute-->
        android:progress="0" />
        android:text="Progress Bar" />

Step 4: Working with the file

  • Go to the file and refer to the following code. 
  • Below is the code for the file. Comments are added inside the code to understand the code in more detail.


import android.os.Bundle;
import android.os.Handler;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
    Handler handler = new Handler();
    public static Button button;
    public static TextView textView;
    public static ImageView img1, img2;
    protected void onCreate(Bundle savedInstanceState) {
        // create a progress bar variable and set the id
        final ProgressBar progressBar = findViewById(;
        // show the progress bar


My Personal Notes arrow_drop_up
Last Updated : 23 Feb, 2021
Like Article
Save Article
Similar Reads
Related Tutorials