android 自定义进度条颜色
先看图
基于产品经理各种自定义需求,经过查阅了解,下面是自己对Android自定义进度条的学习过程!
这个没法了只能看源码了,还好下载了源码, sources\base\core\res\res\ 下应有尽有,修改进度条颜色只能找progress ,因为是改变样式,首先找styles.xml
找到xml后,进去找到
- <span style="font-size: 18px;"> <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></span>
这是默认转圈的效果style,但今天我们修改的是水平进度条颜色!
所以找到
- <span style="font-size: 18px;"> <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></span>
你看系统一步一步关联的,扩展性很性,低耦合,所以我们现在只要改变进度条是怎么样画出来的就行了 ,但是负责画进度条的是
<item name="android:progressDrawable"> 所以我们可以找到"drawable下的 progress_horizontal 文件,改变他就可以改变进度条颜色
- <span style="font-size: 18px;"><?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 at
- http://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>
- </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" 的色值
- <span style="font-size: 18px;"><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></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
android 自定义进度条颜色的更多相关文章
- Android自定义进度条颜色
这个没法了只能看源码了,还好下载了源码, sources\base\core\res\res\ 下应有尽有,修改进度条颜色只能找progress ,因为是改变样式,首先找styles.xml ? 1 ...
- 最简单的android自定义进度条样式
一.自定义圆形进度条样式 1.在安卓项目drawable目录下新建一个xml文件如下:<?xml version="1.0" encoding="utf-8&quo ...
- Android自定义进度条
Android原生控件只有横向进度条一种,而且没法变换样式,比如原生rom的样子很丑是吧,当伟大的产品设计要求更换前背景,甚至纵向,甚至圆弧状的,咋办,比如ok,我们开始吧: 一)变换前背景 先来看看 ...
- Android自定义进度条-带文本(文字进度)的水平进度条(ProgressBar)
水平进度条,显示进度的文本随着进度而移动. 效果如下,截的静态图. 代码如下 TextProgressBar.java public class TextProgressBar extends Pro ...
- android圆形进度条ProgressBar颜色设置
花样android Progressbar http://www.eoeandroid.com/thread-1081-1-1.html http://www.cnblogs.com/xirihanl ...
- BitBlt()函数实现带数字百分比进度条控件、静态文本(STATIC)控件实现的位图进度条、自定义进度条控件实现七彩虹颜色带数字百分比
Windows API BitBlt()函数实现带数字百分比进度条控件. 有两个例子:一用定时器实现,二用多线程实现. 带有详细注解. 此例是本人原创,绝对是网上稀缺资源(本源码用Windows AP ...
- Android 设置进度条背景
Android 设置进度条背景 直接上代码 <ProgressBar android:id="@+id/progressBar" android:layout_width=& ...
- android113 自定义进度条
MainActivity: package com.itheima.monitor; import android.os.Bundle; import android.app.Activity; im ...
- 自定义进度条PictureProgressBar——从开发到开源发布全过程
自定义进度条PictureProgressBar——从开发到开源发布全过程 出处: 炎之铠邮箱:yanzhikai_yjk@qq.com 本文原创,转载请注明本出处! 本项目JCenter地址:htt ...
随机推荐
- SQL SERVER 数据库实用SQL语句
--查看指定表的外键约束 select * from sysobjects where parent_obj in( select id from sysobjects where name='表名' ...
- c#读取Excel的列名问题
在修改c#读取Excel的时候,遇到了一些小问题,总结下,希望别人不用再浪费时间 读取excel的时候,如果是空行就不读取? SELECT * FROM [DB_ESTATE$] where F2&l ...
- Andorid 编程 系统环境安装
内网环境下安装: 1.配置源 :找到公司内部整理的源文件中的内容,将其内容拷贝到系统 源文件 中,并注释掉所有外网链接(如果公司支持内部环境配置,通常会有一个内部源文件) 2.安装jdk, ecli ...
- 在Windows Live Writer中插入C# code
平时都是用Windows Live Writer写博客,发布博客.遇到需要插入代码都是先在notepad中写好,或者是拷贝到notepad,再从notepad中拷到Windows Live Write ...
- 20150625_Andriod_02_ListView2_多条目显示_选中
android listview 参考地址: http://www.cnblogs.com/zhengbeibei/archive/2013/05/14/3078805.html http://xy ...
- Android 查看内存使用状况
再看开发过程中,经常要通过内存的使用量来优化程序. 查看应用程序的命令:adb shell procrank 显示如下: PID Vss Rss Pss Uss ...
- 【Javascript】列表查询页面,简单地保存上一次查询的查询参数
开发中经常做一些查询参数 + 列表参数的功能,这些功能有时候需提供导出Excel,或带超链接到其他明细页面的功能点. 在一些交互性要求严格的系统,需求方会要求: 用户第一个输入某些查询条件进行列表查询 ...
- mysqldump命令
mysqldump命令 mysqldump命令是mysql数据库中备份工具,用于将MySQL服务器中的数据库以标准的sql语言的方式导出,并保存到文件中. 语法 mysqldump(选项) 选项 -- ...
- spring事务管理-摘抄
原著网址 http://gcq04552015.iteye.com/blog/1666570 Spring是以代理的方式实现对事务的管理.我们在Action中所使用的Service对象,其实是代理对象 ...
- 【转载】ogre内存管理
原文:ogre内存管理 OGRE内存分配策略相关文件及简述 OGRE提供了自己的内存分配策略,甚至为STL容器提供了新的分配策略,相关文件及简述如下: OgreMemoryAllocatedObjec ...