Android中圆形和条形ProgressBar设置颜色


目录(?)

圆形

layout中的代码

[html]  view plain copy
  1. <ProgressBar  
  2.  android:layout_width=”wrap_content”  
  3. android:layout_height=”wrap_content”  
  4. android:visibility=”invisible”  
  5. android:layout_centerVertical=”true”  
  6. android:layout_toRightOf=”@id/getMoreTextView”  
  7. android:indeterminateDrawable=”@drawable/progressbar_xml”   
  8. android:id=”@+id/progressbar”  
  9. />  



在Drawable目录下新建xml:progressbar_xml.xml

[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:pivotX="50%" android:pivotY="50%"  
  4.     android:fromDegrees="0"   
  5.     android:toDegrees="360" >  
  6.     <shape android:shape="ring"   
  7.         android:innerRadiusRatio="3"   
  8.         android:thicknessRatio="8"   
  9.         android:useLevel="false">   
  10.         <gradient   
  11.             android:type="sweep"   
  12.             android:useLevel="false"   
  13.             android:startColor="#6BD3FF"   
  14.             android:centerColor="#FFFFFF"   
  15.             android:centerY="0.50"   
  16.             android:endColor="#FFFF00" />   
  17.     shape>   
  18. animated-rotate>  

 

条形

layout中代码

[html]  view plain copy
  1. <ProgressBar  
  2.     android:id="@+id/cacl_progressBar"  
  3.     style="?android:attr/progressBarStyleHorizontal"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="30dp"  
  6.     android:layout_gravity="center_vertical"  
  7.     android:max="100"   
  8.     android:progressDrawable="@drawable/progressbar"  
  9.     android:visibility="gone"/>  

drawable中代码

[html]  view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>   
  2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">   
  3.    
  4. <item android:id="@android:id/background" android:drawable="@drawable/ic_launcher" />   
  5.    
  6. <item android:id="@android:id/secondaryProgress" android:drawable="@drawable/ic_launcher" />   
  7.    
  8. <item android:id="@android:id/progress" android:drawable="@drawable/ic_launcher" />   
  9. layer-list>   

另外一种方法

[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>    
  2.    
  3.     
  4. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">    
  5.       
  6.     <item android:id="@android:id/background">    
  7.         <shape>    
  8.             <corners android:radius="5dip" />   
  9.         <gradient    
  10.                     android:startColor="#ffffffff"    
  11.                     android:centerColor="#fffffff0"    
  12.                     android:centerY="0.75"    
  13.                     android:endColor="#fffffafa"    
  14.                     android:angle="270"    
  15.             />    
  16.         shape>    
  17.     item>    
  18.         
  19.     <item android:id="@android:id/secondaryProgress">    
  20.         <clip>    
  21.             <shape>    
  22.                 <corners android:radius="5dip" />    
  23.                 <gradient    
  24.                         android:startColor="#8000cdcd"    
  25.                         android:centerColor="#8000bfff"    
  26.                         android:centerY="0.75"    
  27.                         android:endColor="#a000b2ee"    
  28.                         android:angle="270"    
  29.                 />    
  30.             shape>    
  31.         clip>    
  32.     item>    
  33.         
  34.     <item android:id="@android:id/progress">    
  35.         <clip>    
  36.             <shape>    
  37.                 <corners android:radius="5dip" />    
  38.                 <gradient    
  39.                         android:startColor="#ff00ffff"    
  40.                         android:centerColor="#ff00ced1"    
  41.                         android:centerY="0.75"    
  42.                         android:endColor="#ff00f5ff"    
  43.                         android:angle="270"    
  44.                 />    
  45.             shape>    
  46.         clip>    
  47.     item>    
  48.          
  49. layer-list>    

更多相关文章

  1. Android之设置页面(PreferenceActivity使用)
  2. ExpandableListView用法实例
  3. 笔记77-listview属性介绍
  4. Android(安卓)登录界面调用输入法时让界面自动上移,使输入法不会
  5. 【Android】android:padding属性设置对ImageButton无效问题
  6. Android(安卓)的系统属性(SystemProperties)设置分析
  7. android 模拟器中启用相机API支持
  8. 去掉WebView中的白色背景
  9. 【eoeAndroid社区索引】android 条形码的知识汇总

随机推荐

  1. python实战课程--控制结构
  2. 在Oracle中,如何判断一个字符串是否为数字
  3. Mybatis 最近知识总结(1)
  4. Gitlab的介绍及使用
  5. MySQL中的limit分页优化
  6. 常用Linux命令集锦
  7. 连接查询详解
  8. 磁盘空间不足的解决办法
  9. CentOS6.5+Python2.7+ GIT +IPython
  10. CPU调优并发问题