An example of this article is a way to implement a custom progress bar color in Android programming. Share to everyone for your reference, specific as follows:
Android Custom progress bar Color
Look at the picture first
Based on a variety of customization requirements of product managers, after consulting, below is their own Android custom progress bar learning process!
This can not only look at the source code, fortunately downloaded the source code, sources\base\core\res\res\, modify the progress bar color can only find progress, because it is to change the style, first find Styles.xml
After you find the XML, go in and find
<style name= "Widget.progressbar" > <item name= "android:indeterminateonly" >true</item> <item Name= "Android:indeterminatedrawable" > @android:d rawable/progress_medium_white</item> <item name= " Android:indeterminatebehavior ">repeat</item> <item name=" Android:indeterminateduration ">3500</ item> <item name= "android:minwidth" >48dip</item> <item name= "Android:maxwidth" >48dip</it em> <item name= "android:minheight" >48dip</item> <item name= "Android:maxheight" >48dip</it em> </style> <style name= "Widget.progressbar" > <item name= "android:indeterminateonly" >true<
/item> <item name= "android:indeterminatedrawable" > @android:d rawable/progress_medium_white</item> <item name= "Android:indeterminatebehavior" >repeat</item> <item name= "Android:indeterminateduration" ">3500</item> <item name="Android:minwidth" >48dip</item> <item name= "android:maxwidth" >48dip</item> <item name= "a
Ndroid:minheight ">48dip</item> <item name=" Android:maxheight ">48dip</item> </style>
This is the default circle effect style, but today we are modifying the horizontal progress bar color!
So find
<style name= "Widget.ProgressBar.Horizontal" > <item name= "android: Indeterminateonly ">false</item> <item name=" android:progressdrawable "> @android:d Rawable/progress_ horizontal</item> <item name= "android:indeterminatedrawable" > @android:d Rawable/progress_ indeterminate_horizontal</item> <item name= "android:minheight" >20dip</item> <item name= "and Roid:maxheight ">20dip</item> </style> <style name=" Widget.ProgressBar.Horizontal "> <item na Me= "Android:indeterminateonly" >false</item> <item name= "android:progressdrawable" > @android: drawable/progress_horizontal</item> <item name= "android:indeterminatedrawable" > @android:d rawable/ progress_indeterminate_horizontal</item> <item name= "Android:minheight" >20dip</item> <item Name= "Android:maxheight" >20dip</item> </style>
You see the system step-by-step associated, extensibility is very low coupling, so we now only change the progress bar is how to draw the line, but is responsible for drawing the progress bar is
<item name= "Android:progressdrawable" > So we can find "drawable under the Progress_horizontal file, change he can change the progress bar color
<?xml version= "1.0" encoding= "Utf-8"?> <!--Copyright (C) 2008 the Android Open Source Project Licensed und
Er the Apache License, Version 2.0 (the "License");
You are not to use this file except in compliance with the License. Obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 unless required by applicable Agreed to writing, software distributed under the License was distributed on ' as is ' basis, without W
Arranties or CONDITIONS of any KIND, either express OR implied.
The License for the specific language governing permissions and limitations under the License. --> <layer-list xmlns:android= "http://schemas.android.com/apk/res/android" > <item android:id= "@android : Id/background "> <shape> <corners android:radius=" 5dip "/> <gradient Andro Id:startcolor= "#ff9d9e9d" android:centercolor= "#ff5a5d5a" android:centery= "0.75 "android:endcolor=" #ff747674 "android:angle=" 270 "/> </shape> </item > <item android:id= "@android: id/secondaryprogress" > <clip> <shape> <corner S android:radius= "5dip"/> <gradient android:startcolor= "#80ffd300" Android:cente Rcolor= "#80ffb600" android:centery= "0.75" android:endcolor= "#a0ffcb00" Android:angl E= "270"/> </shape> </clip> </item> <item android:id= "@android: id/progr
ESS "> <clip> <shape> <corners android:radius=" 5dip "/> <gradient
Android:startcolor= "#ffffd300" android:centercolor= "#ffffb600" android:centery= "0.75" Android:endcolor= "#ffffcb00" android:angle= "270"/> </shape> </ Clip> </item>
</layer-list>
<?xml version= "1.0" encoding= "Utf-8"?> <!--Copyright (C) 2008 the Android Open Source Project Licensed und
Er the Apache License, Version 2.0 (the "License");
You are not to use this file except in compliance with the License. Obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 unless required by applicable Agreed to writing, software distributed under the License was distributed on ' as is ' basis, without W
Arranties or CONDITIONS of any KIND, either express OR implied.
The License for the specific language governing permissions and limitations under the License. --> <layer-list xmlns:android= "http://schemas.android.com/apk/res/android" > <item android:id= "@android : Id/background "> <shape> <corners android:radius=" 5dip "/> <gradient Andro Id:startcolor= "#ff9d9e9d" android:centercolor= "#ff5a5d5a" android:centery= "0.75 "android:endcolor=" #ff747674 "android:angle=" 270 "/> </shape> </item > <item android:id= "@android: id/secondaryprogress" > <clip> <shape> <corner S android:radius= "5dip"/> <gradient android:startcolor= "#80ffd300" Android:cente Rcolor= "#80ffb600" android:centery= "0.75" android:endcolor= "#a0ffcb00" Android:angl E= "270"/> </shape> </clip> </item> <item android:id= "@android: id/progr
ESS "> <clip> <shape> <corners android:radius=" 5dip "/> <gradient
Android:startcolor= "#ffffd300" android:centercolor= "#ffffb600" android:centery= "0.75" Android:endcolor= "#ffffcb00" android:angle= "270"/> </shape> </ Clip> </item>
</layer-list>
See no, this is the system's progress bar to draw out the layout conditions
Android:startcolor= "#80ffd300"
android:centercolor= "#80ffb600"
android:endcolor= "#ff747674"
As long as we change this color value can change his color, the main change is <item android:id= "@android: id/progress" color value on the line
Say so much, exactly how to do it, very simple
1. Create a new Style.xml file under our project
Create a style label, integrate the system default style, and then customize a new Progressdrawable file, and then refer to the file in the progress in layout.
<style name= "Progressbar_mini" parent= "@android: Style/widget.progressbar.horizontal" >
<item name= " Android:maxheight ">50dip</item>
<item name=" Android:minheight ">8dip</item>
< Item Name= "Android:indeterminateonly" >false</item>
<item name= "Android:indeterminatedrawable" > @android:d rawable/progress_indeterminate_horizontal</item>
<item name= "Android: Progressdrawable "> @drawable/progressbar_mini</item>
</style>
Below is my progressbar_mini file, changing the color value of the "#F5F5F5" android:startcolor= "#BEBEBE" below android:endcolor=
<layer-list xmlns:android= "Http://schemas.android.com/apk/res/android" > <item android:id= "@android: Id/ Background "> <shape > <corners android:radius=" 5dip "/> <gradient and Roid:angle= "270" android:centery= "0.75" android:endcolor= "#F5F5F5" android:startcolor= "#B Ebebe "/> </shape> </item> <item android:id=" @android: id/secondaryprogress "> <cl IP > <shape > <corners android:radius= "0dip"/> <gradient android:an Gle= "270" android:centery= "0.75" android:endcolor= "#165CBC" android:startcolor= "#85B0E9" /> </shape> </clip> </item> <item android:id= "@android: Id/progress" > ; clip > <shape > <corners android:radius= "5dip"/> <gradient Android : angle= "270" Android:centery= "0.75" android:endcolor= "#165CBC" android:startcolor= "#85B0E9"/> </shape> </clip> </item> </layer-list> <layer-list xmlns:android= "Http://schemas.android.com/apk/res /android "> <item android:id=" @android: Id/background "> <shape > <corners android:radiu s= "5dip"/> <gradient android:angle= "270" android:centery= "0.75" android:e Ndcolor= "#F5F5F5" android:startcolor= "#BEBEBE"/> </shape> </item> <item android : id= "@android: id/secondaryprogress" > <clip > <shape > <corners android:radius= "0dip "/> <gradient android:angle=" 270 "android:centery=" 0.75 "Android:endcolor" = "#165CBC" android:startcolor= "#85B0E9"/> </shape> </clip> </item> < Item Android:id= "@androiD:id/progress "> <clip > <shape > <corners android:radius=" 5dip "/> <
Gradient android:angle= "270" android:centery= "0.75" android:endcolor= "#165CBC"
Android:startcolor= "#85B0E9"/> </shape> </clip> </item> </layer-list>
Finally, in the reference to the
<progressbar
android:id= "@+id/progress"
style= "@style/progressbar_mini" android:layout_width= "
Fill_parent "
android:layout_height=" wrap_content "
android:progress="/>
I hope this article will help you with the Android program.