Android ProgressBar 自定义样式(一)

在android项目开发中经常要用到ProgressBar,如果用默认的设置,由于android的开源性,导致不同的手机厂商的显示是不一样的,这样不太好,于是我们可以定义我们想要的效果。

先上图:

  要达到这种小效果很简单,只要在xml文件里面配置一下就可以了,方法如下:

在activity的布局文件:

[html]  view plain copy
  1. <ProgressBar  
  2.             android:id="@+id/progressBar2"  
  3.             android:layout_width="wrap_content"  
  4.             android:layout_height="wrap_content"  
  5.             android:indeterminate="false"  
  6.             android:indeterminateDrawable="@drawable/my_progress_bar_color" />  

其中my_progress_bar_color的文件在drawable文件下,如下:

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


[html]  view plain copy
  1. 我们可以在gradient属性里面配置我们想要的颜色,很简单,就不多说了。  

猜你喜欢

转载自blog.csdn.net/wypeng2010/article/details/47040459