Android custom progress bar color
First look at the figure
I always asked a variety of requirements. I think the default color of the system is quite good, but the PK is not good. sleeping is not a requirement. Let's change it!
You can only view the source code, but you can download the source code. You can only find progress to modify the progress bar color, because it is to change the style, first, find styles. XML
Find the XML and go in and find
<style name="Widget.ProgressBar"> <item name="android:indeterminateOnly">true</item> <item name="android:indeterminateDrawable">@android:drawable/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="android:minHeight">48dip</item> <item name="android:maxHeight">48dip</item> </style>
Which of the following is the default circle, but today we will not modify this. We need to change the horizontal progress bar color.
So find
<style name="Widget.ProgressBar.Horizontal"> <item name="android:indeterminateOnly">false</item> <item name="android:progressDrawable">@android:drawable/progress_horizontal</item> <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item> <item name="android:minHeight">20dip</item> <item name="android:maxHeight">20dip</item> </style>
You can see that the system is associated step by step, with scalability and low coupling. So now we only need to change how the progress bar is drawn, but what is responsible for drawing the progress bar?
<Item name = "Android: progressdrawable"> so we can find the progress_horizontal file under drawable and change the progress bar color.
<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2008 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See 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 android: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> <corners android:radius="5dip" /> <gradient android:startColor="#80ffd300" android:centerColor="#80ffb600" android:centerY="0.75" android:endColor="#a0ffcb00" android:angle="270" /> </shape> </clip> </item> <item android:id="@android:id/progress"> <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>
No. 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 its color. The main change is the color value under <item Android: Id = "@ Android: ID/progress">.
After talking about this, how can we do it? It's very simple.
1. Create a style. xml file in our project
Create a style label, integrate the system default style, and then customize a new progressdrawable file. Then, reference this 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: drawable/progress_indeterminate_horizontal </item>
<Item name = "Android: progressdrawable"> @ drawable/progressbar_mini </item>
</Style>
The following is my progressbar_mini file, which changes the color value of Android: endcolor = "# f5f5f5" Android: startcolor = "# Bebebebe ".
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@android:id/background"> <shape > <corners android:radius="5dip" /> <gradient android:angle="270" android:centerY="0.75" android:endColor="#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, you can reference it in.
<Progressbar
Android: Id = "@ + ID/progress"
Style = "@ style/progressbar_mini"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: Progress = "50"/>
Reprinted statement initial entry: http://blog.csdn.net/liao3841054/article/details/7556551
Leave an email address for the demo or give your comments: Thank you.