android 自定义进度条颜色

先看图

基于产品经理各种自定义需求,经过查阅了解,下面是自己对Android自定义进度条的学习过程!

 

这个没法了只能看源码了,还好下载了源码, sources\base\core\res\res\  下应有尽有,修改进度条颜色只能找progress ,因为是改变样式,首先找styles.xml

找到xml后,进去找到

[html] view plaincopyprint?

  1. <span style="font-size: 18px;">    <style name="Widget.ProgressBar">
  2. <item name="android:indeterminateOnly">true</item>
  3. <item name="android:indeterminateDrawable">@android:drawable/progress_medium_white</item>
  4. <item name="android:indeterminateBehavior">repeat</item>
  5. <item name="android:indeterminateDuration">3500</item>
  6. <item name="android:minWidth">48dip</item>
  7. <item name="android:maxWidth">48dip</item>
  8. <item name="android:minHeight">48dip</item>
  9. <item name="android:maxHeight">48dip</item>
  10. </style></span>

这是默认转圈的效果style,但今天我们修改的是水平进度条颜色!

所以找到

[html] view plaincopyprint?

  1. <span style="font-size: 18px;"> <style name="Widget.ProgressBar.Horizontal">
  2. <item name="android:indeterminateOnly">false</item>
  3. <item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
  4. <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
  5. <item name="android:minHeight">20dip</item>
  6. <item name="android:maxHeight">20dip</item>
  7. </style></span>

你看系统一步一步关联的,扩展性很性,低耦合,所以我们现在只要改变进度条是怎么样画出来的就行了 ,但是负责画进度条的是

<item name="android:progressDrawable">  所以我们可以找到"drawable下的 progress_horizontal 文件,改变他就可以改变进度条颜色

[java] view plaincopyprint?

  1. <span style="font-size: 18px;"><?xml version="1.0" encoding="utf-8"?>
  2. <!-- Copyright (C) 2008 The Android Open Source Project
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. -->
  13. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  14. <item android:id="@android:id/background">
  15. <shape>
  16. <corners android:radius="5dip" />
  17. <gradient
  18. android:startColor="#ff9d9e9d"
  19. android:centerColor="#ff5a5d5a"
  20. android:centerY="0.75"
  21. android:endColor="#ff747674"
  22. android:angle="270"
  23. />
  24. </shape>
  25. </item>
  26. <item android:id="@android:id/secondaryProgress">
  27. <clip>
  28. <shape>
  29. <corners android:radius="5dip" />
  30. <gradient
  31. android:startColor="#80ffd300"
  32. android:centerColor="#80ffb600"
  33. android:centerY="0.75"
  34. android:endColor="#a0ffcb00"
  35. android:angle="270"
  36. />
  37. </shape>
  38. </clip>
  39. </item>
  40. <item android:id="@android:id/progress">
  41. <clip>
  42. <shape>
  43. <corners android:radius="5dip" />
  44. <gradient
  45. android:startColor="#ffffd300"
  46. android:centerColor="#ffffb600"
  47. android:centerY="0.75"
  48. android:endColor="#ffffcb00"
  49. android:angle="270"
  50. />
  51. </shape>
  52. </clip>
  53. </item>
  54. </layer-list>
  55. </span>

看到没有,这是系统的进度条画出的布局条件

android:startColor="#80ffd300"

android:centerColor="#80ffb600"

android:endColor="#ff747674"

我们只要改变这个色值就能改变他的颜色,主要改变的是<item android:id="@android:id/progress">下的色值就行了

说了这么多,到底怎么做呢, 很简单

1  。 在我们的项目下新建一个 style.xml 文件

创建一个style 标签,集成系统默认样式,然后自定义一个新的progressDrawable  文件,随后面在layout 中的progress 中引用这个文件就行

<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"  的色值

[java] view plaincopyprint?

  1. <span style="font-size: 18px;"><layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
  2. <item android:id="@android:id/background">
  3. <shape >
  4. <corners android:radius="5dip" />
  5. <gradient
  6. android:angle="270"
  7. android:centerY="0.75"
  8. android:endColor="#F5F5F5"
  9. android:startColor="#BEBEBE" />
  10. </shape>
  11. </item>
  12. <item android:id="@android:id/secondaryProgress">
  13. <clip >
  14. <shape >
  15. <corners android:radius="0dip" />
  16. <gradient
  17. android:angle="270"
  18. android:centerY="0.75"
  19. android:endColor="#165CBC"
  20. android:startColor="#85B0E9" />
  21. </shape>
  22. </clip>
  23. </item>
  24. <item android:id="@android:id/progress">
  25. <clip >
  26. <shape >
  27. <corners android:radius="5dip" />
  28. <gradient
  29. android:angle="270"
  30. android:centerY="0.75"
  31. android:endColor="#165CBC"
  32. android:startColor="#85B0E9" />
  33. </shape>
  34. </clip>
  35. </item>
  36. </layer-list></span>

最后在中引用就可以了

<ProgressBar
        android:id="@+id/progress"
        style="@style/ProgressBar_Mini"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:progress="50" />

转载申明初入:http://blog.csdn.net/liao3841054/article/details/7556551

0
0
时间: 2024-08-01 22:47:44

android 自定义进度条颜色的相关文章

Android自定义进度条样式

最近在做一个widget,上面需要一个progressbar,产品经理和设计师给出来的东西是要实现一个圆角的progress和自定义的颜色,研究一小下,分享出来给大家哦. 测试于:Android4.0+ 操作步骤: 1.创建你的layout文件引用progressbar如下,标红处引用你自定的样式: <ProgressBar android:id="@+id/progressDownload" style="?android:attr/progressBarStyleH

Android自定义进度条-带文本(文字进度)的水平进度条(ProgressBar)

/** * 带文本提示的进度条 */ public class TextProgressBar extends ProgressBar { private String text; private Paint mPaint; public TextProgressBar(Context context) { super(context); initText(); } public TextProgressBar(Context context, AttributeSet attrs, int d

最简单的android自定义进度条样式

一.自定义圆形进度条样式 1.在安卓项目drawable目录下新建一个xml文件如下:<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:pivotX="50%" android:pivotY="50%" andro

Android 自定义进度条,

最近工作繁忙,一直都埋头在工作中,也不知这么热心工作究竟是为了什么,不知不觉的,到今天才晓得夏天已经来了.天气热,心也热. 网络上出个牛人,辞职信上写着:世界那么大,我想去看看.由衷的佩服她的勇气,我也想去看看这大千世界,可惜我们总是身不由己,有太多的放不下,或许哪天放下了,我也出去走走. 之前一直以为罗永浩是个逗比,直到前两天看了他几期演讲,才发现逗比一直是我.他有句话我很欣赏,这里也分享给大家:在什么样的年纪,就做什么样的事情,怎么能在每个阶段都做错呢!PS:该玩的年纪玩,该谈恋爱的年纪谈恋

自定义进度条\文字描边样式\文字上下滚动TextSwithcher的应用

一.自定义进度条 1.<ProgressBar         android:id="@+id/patch_progress"         style="@style/gxProgressStyle"         android:layout_width="match_parent"         android:layout_height="12dp"         android:layout_alig

自定义进度条PictureProgressBar——从开发到开源发布全过程

自定义进度条PictureProgressBar--从开发到开源发布全过程 出处: 炎之铠邮箱:[email protected] 本文原创,转载请注明本出处! 本项目JCenter地址:https://bintray.com/yanzhikaijky/CustomViewRepository/PictureProgressbar/ 本项目GitHub地址:https://github.com/totond/PictureProgressBar 欢迎 Star or Fork和在Issue里提出

自定义进度条(圆形、横向进度条)

自定义进度条实现大体流程 1.自定义属性声明(attrs文件) 2.自定义属性获取 3.测量(onMeasure) 4.绘制(onDraw) 代码: attrs文件: <!-- 自定义声明 --> <attr name="progress_unreach_color" format="color"></attr> <attr name="progress_unreach_height" format=&q

android113 自定义进度条

MainActivity: package com.itheima.monitor; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.ProgressBar; public class MainActivity extends Activity { private MyProgressBa

[Android]组件-进度条1

多式样ProgressBar 普通圆形ProgressBar 该类型进度条也就是一个表示运转的过程,例如发送短信,连接网络等等,表示一个过程正在执行中. 一般只要在XML布局中定义就可以了. <progressBar android:id="@+id/widget43" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layou