Get the App
SLTechnology News&Howtos  ›  Development  › 

How to customize the progress bar color in Android

Shulou Source: shulou.com Published: 2022-05-31 22:03:26 10月03日 Update

This article mainly introduces "how to customize the color of the progress bar in Android". In the daily operation, I believe that many people have doubts about how to customize the color of the progress bar in Android. The editor consulted all kinds of materials and sorted out a simple and easy-to-use method of operation. I hope it will be helpful to answer the doubt of "how to customize the color of progress bar in Android". Next, please follow the editor to study!

Styles.xml

When you find xml, go in and find:

True @ android:drawable/progress_medium_white repeat 3500 48dip 48dip 48dip 48dip

This is the default circle, but today we will not modify this, we are going to change the color of the horizontal progress bar, so find:

False @ android:drawable/progress_horizontal @ android:drawable/progress_indeterminate_horizontal 20dip 20dip

You see, the system is related step by step, with very high expansibility and low coupling, so now we just need to change how the progress bar is drawn, but the one responsible for drawing the progress bar is so that we can find the progress_horizontal file under drawable, change it and change the color of the progress bar.

See, this is the layout condition drawn by the progress bar of the system.

Android:startColor= "# 80ffd300" android:centerColor= "# 80ffb600" android:endColor= "# ff747674"

We only need to change this color value to change his color, the main change is the lower color value.

After all that has been said, how to do it is very simple:

Create a new style.xml file under our project

Create a style tag, integrate the system default style, and then customize a new progressDrawable file, which can be referenced later in progress in layout.

50dip 8dip false @ android:drawable/progress_indeterminate_horizontal @ drawable/progressbar_mini

Here is my progressbar_mini file, which changes the color value of android:endColor= "# F5F5F5" android:startColor= "# BEBEBE"

Finally, just quote it.

At this point, the study on "how to customize the color of the progress bar in Android" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Progress colors files learning systems more this is help practical next layout extensibility articles methods conditions labels styles levels theory knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Docker Linux MariaDB macOS