網上收集的文章:http://www.bkjia.com/Androidjc/889841.html
1.改變Progress可以通過改寫樣式的方式,首先看Android自己的進度條樣式
樣式中的參數介紹
<style name="Widget.ProgressBar.Horizontal">
<item name="android:indeterminateOnly">false</item>
<item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
<item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
<item name="android:minHeight">20dip</item>
<item name="android:maxHeight">20dip</item>
</style>
android:max=”100” 進度條的最大值
android:progress 進度條已經完成的進度值
android:progressDrawable 已經完成的進度條軌道顯示的Drawable對象
indeterminateDrawable 設置繪製不顯示進度的進度條的Drawable對象
android:indeterminate 設置爲true,進度條不精準顯示進度
android:indeterminateDuration 設置不精準顯示進度的時間
下面來看資源文件@android:drawable/progress_horizontal
background對應進度條灰色的部分,既背景
secondaryProgress:進度條緩衝時,灰色的部分,圖片中沒有
progress:對應進度條的樣子
<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>
所以如果想改變一個進度條的樣式,可以通過自定義一個drawable文件,重寫裏面的drawable資源
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@android:id/background"
android:drawable="@drawable/security_progress_bg"/>
<item android:id="@android:id/progress" android:drawable="@drawable/security_progress"/>
</layer-list>
並且在新的資源上引用到你的樣式中
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@android:id/background"
android:drawable="@drawable/security_progress_bg"/>
<item
android:id="@android:id/progress"
android:drawable="@drawable/security_progress"/>
</layer-list>
給你的progressbar引用新的樣式
<ProgressBar
android:id="@+id/progressBar1"
style="@style/my_pb_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />