先看效果图:
老是提些各种需求问题,我觉得系统默认的颜色挺好的,但是Pk不过,谁叫我们不是需求人员呢,改吧!
这个没法了只能看源码了,还好下载了源码, sources\base\core\res\res\ 下应有尽有,修改进度条颜色只能找progress ,因为是改变样式,首先找styles.xml
找到xml后,进去找到:
1
2
3
4
5
6
7
8
9
10
|
< 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 >
|
这是那个默认转圈的,但今天我们不修改这个,我们是要改变水平进度条颜色,所以找到:
1
2
3
4
5
6
7
|
< 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 >
|
你看系统一步一步关联的,扩展性很性,低耦合,所以我们现在只要改变进度条是怎么样画出来的就行了 ,但是负责画进度条的是 <item name="android:progressDrawable"> 所以我们可以找到"drawable下的 progress_horizontal 文件,改变他就可以改变进度条颜色。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
<? xml version = "1.0" encoding = "utf-8" ?>
< item android:id = "@android:id/background" >
< shape >
< corners android:radius = "5dip" />
< gradient
android:angle = "270"
android:centerColor = "#ff5a5d5a"
android:centerY = "0.75"
android:endColor = "#ff747674"
android:startColor = "#ff9d9e9d" />
</ shape >
</ item >
< item android:id = "@android:id/secondaryProgress" >
< clip >
< shape >
< corners android:radius = "5dip" />
< gradient
android:angle = "270"
android:centerColor = "#80ffb600"
android:centerY = "0.75"
android:endColor = "#a0ffcb00"
android:startColor = "#80ffd300" />
</ shape >
</ clip >
</ item >
< item android:id = "@android:id/progress" >
< clip >
< shape >
< corners android:radius = "5dip" />
< gradient
android:angle = "270"
android:centerColor = "#ffffb600"
android:centerY = "0.75"
android:endColor = "#ffffcb00"
android:startColor = "#ffffd300" />
</ shape >
</ clip >
</ item >
</ layer-list >
|
看到没有,这是系统的进度条画出的布局条件
1
2
3
|
android:startColor="#80ffd300"
android:centerColor="#80ffb600"
android:endColor="#ff747674"
|
我们只要改变这个色值就能改变他的颜色,主要改变的是<item android:id="@android:id/progress">下的色值就行了。
说了这么多,到底怎么做呢,很简单:
在我们的项目下新建一个 style.xml 文件
创建一个style 标签,集成系统默认样式,然后自定义一个新的progressDrawable 文件,随后面在layout 中的progress 中引用这个文件就行。
1
2
3
4
5
6
7
|
< 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 >
|
下面是我的 progressbar_mini 文件,改变了下android:endColor="#F5F5F5" android:startColor="#BEBEBE" 的色值
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
< 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 >
|
最后引用其就可以了。
1
2
3
4
5
6
|
< ProgressBar
android:id = "@+id/progress"
style = "@style/ProgressBar_Mini"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:progress = "50" />
|
分享到:
相关推荐
自定义多彩进度条
基于产品经理各种自定义需求,经过查阅了解,下面是自己对android自定义进度条的学习过程! 这个没法了只能看源码了,还好下载了源码, sources\base\core\res\res\ 下应有尽有,修改进度条颜色只能找progress ,...
Android自定义进度条样式,通过修改图片颜色,无锯齿
RingProgressView 自定义环形进度条,支持自定义进度条颜色、当前进度颜色、百分比文本
http://blog.csdn.net/yanjunhui2011/article/details/56016414 ...该自定义组件的优势: 1、使用简单; 2、可随意改变圆点、直线的颜色和大小; 当然,也许你会吐槽,系统不是提供了 seekBar 吗,怎么不用 seekBar。
自定义椭圆形进度条,通过自定义控件,自定义进度条颜色,自定义文字颜色,进度之前和进度之后的字体颜色进行区分
本文实例讲述了Android编程自定义进度条颜色的方法。分享给大家供大家参考,具体如下: 先看效果图: 老是提些各种需求问题,我觉得系统默认的颜色挺好的,但是Pk不过,谁叫我们不是需求人员呢,改吧! 这个没法了...
// 绘制白色圆圈,即进度条背景 paint.setColor(Color.rgb(0x57, 0x87, 0xb6)); paint.setStrokeWidth(marxArcStorkeWidth); canvas.drawArc(oval, -90, ((float) progress / maxProgress) * 360, false, paint...
1.本文将向你介绍自定义进度条的写法,比较简单,但还是有些知识点是需要注意的: invalidate()方法 RectF方法的应用 onMeasure方法的应用 2.原理 画3层圆角矩形,底层为黑色,第二层为灰色,最上一层为进度条颜色,...
可实现自定义进度条的颜色,倒角,有无边线,进度条上是否显示文字进度等等,效果不错
自定义分段进度条:1.可以根据权重设置不同段的大小;2.可以设置进度到某段时进度条显示的颜色;
通过layer-list实现的自定义颜色的 ProgressBar,效果还不错!
最近项目中需要在一个功能模块中使用进度条,效果图如下: 上面图片从左到右分别是效果一,效果二,效果三 需求: 以下四点需要实现 1: 当没有没完成进度的时候,显示效果一 2:当进度完成了一部分,显示图...
今天小编来手写一个自定义圆形进度条:先看效果: 首先我们在attrs属性文件中增加几个自定义属性 <?xml version=1.0 encoding=utf-8?> <!-- 圆形进度条进度显示的颜色 --> ...
通过自定义progressBar,draw文字的同时,让文字随着进度条的增加,颜色产生渐变
在安全卫生上,经常看到有圆形的进度条在转动,效果非常好看,于是就尝试去实现一下,具体实现过程不多说了,直接上效果图,先炫耀下。 效果图: 分析:比较常见于扫描结果、进度条等场景 利用canvas.drawArc(RectF...
Android 圆形颜色渐变进度条 自定义控件 博客地址见: http://blog.csdn.net/wangchunlei123/article/details/50478913
自定义进度条,进度条背景颜色的自定义,也可以对进度条的颜色进行自定义。