二话不说先上图
progressbar.jpg
1.布局代码
<ProgressBar
android:id="@+id/pb_progressbar"
style="@style/mProgressBarStyle"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_20"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:progressDrawable="@drawable/main_pb_bg"
android:max="100"
android:progress="40"/>
2.在res下的values中找到style.xml
添加以下代码
<style name="mProgressBarStyle" parent="@android:style/Widget.ProgressBar.Horizontal">
<item name="android:maxHeight">50dp</item>
<item name="android:minHeight">10dp</item>
<item name="android:indeterminateOnly">false</item>
<item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
</style>
3.在drawable中新建main_pb_bg.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--pb背景样式-->
<item
android:id="@android:id/background"
android:drawable="@drawable/pgs_bar_bg" />
<!--pb进度条样式-->
<item android:id="@android:id/progress">
<scale
android:drawable="@drawable/shape_pgsb"
android:scaleWidth="100%" />
</item>
</layer-list>
3.在drawable中新建pgs_bar_bg.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="30dp" />
<solid android:color="#0EBF7E" />
</shape>
4.在drawable新建shape_pgsb.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="30dp" />
<solid android:color="#EA0909" />
</shape>
根据需要自己修改各项参数即可!
网友评论