Customizing the Programs Bar

Asked 2 years ago, Updated 2 years ago, 102 views

You want to use ProgressBar for the app you are currently building. I want to use customized ProgressBar instead of ProgressBar provided by Android, how do I do it?

Do I need to work on graphics or animation?

I tried to refer to the article below, but it failed.

Custom Progress bar Android

android progress-bar

2022-09-21 20:06

1 Answers

An example is described in the blog on the right link with a code: Customized Progress Bar In Android

To customize ProgressBar, you must define the background of the loading bar and properties for the loading image.

Create customprogressbar.xml in the res->drawable directory.

custom_progressbar.xmll

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Define the background properties like color etc -->
    <item android:id="@android:id/background">
    <shape>
        <gradient
                android:startColor="#000001"
                android:centerColor="#0b131e"
                android:centerY="1.0"
                android:endColor="#0d1522"
                android:angle="270"
        />
    </shape>
   </item>

  <!-- Define the progress properties like start color, end color etc -->
  <item android:id="@android:id/progress">
    <clip>
        <shape>
            <gradient
                android:startColor="#007A00"
                android:centerColor="#007A00"
                android:centerY="1.0"
                android:endColor="#06101d"
                android:angle="270"
            />
        </shape>
    </clip>
    </item>
</layer-list>

You must now set progressDrawable to customprogressbar.xml. This can be done from an XML file or activity.

Insert the code below into the XML file:

<ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleHorizontal"
    android:progressDrawable="@drawable/custom_progressbar"         
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

Insert the code below into the Java code

// recall custom_progressbar
    Drawable draw=res.getDrawable(R.drawable.custom_progressbar);
// Set loading image
    progressBar.setProgressDrawable(draw);


2022-09-21 20:06

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.