自定义progressbar样式

老式水平样式(比较粗) style= "@android:style/Widget.ProgressBar.Horizontal"
新式水平样式(比较美观) style= "?android:attr/progressBarStyleHorizontal"
老式水平样式(颜色)改变:
@android:style/Widget.ProgressBar.Horizontal
--->
<item name= "progressDrawable" > @drawable/progress_horizontal </item>
--->
<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>
//应用
<ProgressBar
android :layout_marginTop= "10dp"
android :layout_width= "match_parent"
android :layout_height= "wrap_content"
style= "@android:style/Widget.ProgressBar.Horizontal"
android :progressDrawable= "@drawable/xin_styleprogressbar_layout"
android :max= "100"
android :progress= "30"
android :secondaryProgress= "60"
android :maxHeight= "3dp"
android :minHeight= "3dp"
/>



老式水平样式改变:
@android:style/Widget.ProgressBar.Horizontal
--->
<item name= "progressDrawable" > @drawable/progress_horizontal </item>
--->
<layer-list xmlns: android = "http://schemas.android.com/apk/res/android" >
<item
android :id= "@android:id/background"
android :drawable= "@drawable/android_1512_background"
/>

<item
android :id= "@android:id/progress"
android :drawable= "@drawable/android_1512_font"
/>
</layer-list>
在代码中追加:
ProgressBar bar ;
Handler handler = new Handler(){
@Override
public void handleMessage (Message msg) {
if ( bar .getProgress() == 100 ){
bar .setProgress( 0 ) ;
} else {
bar .setProgress( bar .getProgress()+ 1 ) ;

}
handler .sendEmptyMessageDelayed( 0 , 100 ) ;
}
} ;
@Override
protected void onCreate (Bundle savedInstanceState) {
super .onCreate(savedInstanceState) ;
setContentView(R.layout. activity_main ) ;
bar = (ProgressBar) findViewById(R.id. mypb ) ;
handler .sendEmptyMessage( 0 ) ;
}
//应用:
<ProgressBar
android :layout_marginTop= "10dp"
android :layout_width= "300dp"
android :layout_height= "96dp"
style= "@android:style/Widget.ProgressBar.Horizontal"
android :progressDrawable= "@drawable/newstyle"
android :max= "100"
android :id= "@+id/mypb"
/>



默认样式 style= "@android:style/Widget.ProgressBar"
更改: style= "@android:style/Widget.ProgressBar"
--->
//该文件在F:\adt\adt-bundle-windows-x86_64-20140702\sdk\platforms\android-20\data\res\drawable中打开
<item name= "indeterminateDrawable" > @drawable/progress_medium_white </item>
如下:
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/spinner_white_48"
android:pivotX="50%"
android:pivotY="50%"
android:framesCount="12"
android:frameDuration="100" />
将 android:drawable改为自定义图片
--->
<rotate xmlns: android = "http://schemas.android.com/apk/res/android"
android :drawable= "@drawable/loading_32dp"
android :pivotX= "50%"
android :pivotY= "50%"
/>
//应用
<ProgressBar
android :layout_marginTop= "10dp"
android :layout_width= "match_parent"
android :layout_height= "wrap_content"
style= "@android:style/Widget.ProgressBar"
android :indeterminateDrawable= "@drawable/circle_layout"
android :indeterminateDuration= "1000"
/>

最终效果图:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值