1 <ProgressBar 2 android:id="@+id/progress_bar" 3 style="?android:attr/progressBarStyleHorizontal" <!--必须设置为水平--> 4 android:progressDrawable="@drawable/myprogress" <!--此处用自定义样式--> 5 android:layout_width="158dp" 6 android:layout_height="5dp" 7 android:layout_marginTop="5dp" 8 android:maxHeight="5dp" 9 android:minHeight="5dp" 10 android:max="100" 11 android:secondaryProgress="0" 12 android:progress="0" 13 android:indeterminateOnly="false" />
1 <?xml version="1.0" encoding="utf-8"?> 2 <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 3 <!--item background与progress 顺序不可颠倒 --> 4 <item android:id="@android:id/background" > 5 <shape android:shape="line"> 6 <stroke 7 android:width="4dp" android:color="#666666" <!--背景颜色和宽度--> 8 android:dashWidth="4dp" android:dashGap="1dp" /> <!--虚线间隔1dp--> 9 </shape> 10 </item> 11 <item android:id="@android:id/progress" > 12 <clip> 13 <shape android:shape="line"> 14 <stroke 15 android:width="4dp" android:color="#000000" 16 android:dashWidth="4dp" android:dashGap="1dp" /> 17 </shape> 18 </clip> 19 </item> 20 </layer-list>