自定义Android进度条ProgressBar样式

进度条在Android应用中随处或见,都是为用户提供一个提示,用来增加用户的体验度!进度条样式多种多样,有圆形的,有条形的,有垂直方向的,也有水平方向的。Android系统也是我们提供了好几种默认的样式,今天我们来讲讲自定义样式的ProgressBar。

下面用个很小(又是很小)的例子:

————————-xml布局——————————————–

<ProgressBar android:id="@+id/total_pb_avage" style="@android:style/Widget.ProgressBar.Horizontal" android:layout_width="match_parent" android:layout_height="3.5dp" android:layout_marginLeft="10dp" android:layout_marginRight="15dp" android:layout_marginTop="4dp"

android:max="100"

android:progress="20"

android:progressDrawable="@drawable/progress_bar_background" />

相关属性介绍:

style是指定进度条风格,系统提供的有以下几种:

style="@android:style/Widget.ProgressBar.Small" /**小型圆形进度条*/

style="@android:style/Widget.ProgressBar.Small.Inverse" /**小型圆形进度条*/

style="@android:style/Widget.ProgressBar.Inverse"  /**中型圆形进度条*/

style="@android:style/Widget.ProgressBar.Large"  /**大型圆形进度条*/

style="@android:style/Widget.ProgressBar.Large.Inverse" /**大型圆形进度条*/

style="@android:style/Widget.ProgressBar.Horizontal"  /**水平进度条*/

android:max=""用来指定进度条的最大值

android:progress=""用来指定当前进度

android:progressDrawable=""就是今天的关键,用来指定图片样式,包括进行中的样式,,我们自定义样式主要是在这个上面做文章:

—————-自定义样式在drawable文件下面progress_bar_background.xml————————

<layer-list xmlns:android="" > <item android:id="@android:id/background"><!– 正常情况下的效果–> <shape> <corners android:radius="2dip" /><!– 设置圆角半径–> <gradient<!– 设置渐变效果–> android:angle="270" android:centerColor="#e5e5e5" android:centerY="2.0" android:endColor="#e5e5e5" android:startColor="#e5e5e5" /> </shape> </item> <item android:id="@android:id/progress"><!– 时行中的效果–> <clip> <shape> <corners android:radius="2dip" /> <gradient android:angle="270" android:centerColor="#e12328" android:centerY="2.0" android:endColor="#e12328" android:startColor="#e12328" /> </shape> </clip> </item></layer-list>

——————–代码中就很简单啦————————-

private ProgressBar mPbar;

mPbar=findViewById(R.id.total_pb_avage);

mPbar.setProgress(xxx);//xxx是你要显示的数值,数值部分就会显示红色的效果

快乐要懂得分享,才能加倍的快乐

自定义Android进度条ProgressBar样式

相关文章:

你感兴趣的文章:

标签云: