Search code examples
androidcustomizationandroid-progressbar

How to customize a progressbar in android


How to create a customized indeterminate progress bar in android? I described it below to show you how you can use a customized progress bar in android


Solution

  • To create a customized ProgressBar in android I've used this method

    1- create an image file (custom_blue.png) which is replace with default indeterminate ProgressBar enter image description here

    2- create a xml file into drawable with this code(my_progress_indeterminate.xml):

    <?xml version="1.0" encoding="utf-8"?>
    <animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:drawable="@drawable/custom_blue"
        android:pivotX="50%"
        android:pivotY="50%" />
    

    3- insert a ProgressBar into your layout

    <ProgressBar
        android:id="@+id/custom_progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:indeterminateBehavior="repeat"
        android:indeterminateDrawable="@drawable/my_progress_indeterminate"
        android:maxHeight="24dp"
        android:maxWidth="24dp"
        android:minHeight="24dp"
        android:minWidth="24dp" />
    

    4- that's all. now use this ProgressBar as before in your java Activity