android系统提供了少量的progressBar样式,但是样式有限,而且不够美观。所以这就需要我们自已定义progressBar的风格。提高应用UI的美观。这里简单的介绍自定义progressBar的两种方式。
一、替换默认样式
首先看android系统内部progressBar样式
<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>
<item name="android:mirrorForRtl">true</item>
</style>@android:drawable/progress_horizontal.xml<?xml version="1.0" encoding="utf-8"?>
<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>
@android:drawable/progress_indeterminate_horizontal
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/progressbar_indeterminate1" android:duration="200" />
<item android:drawable="@drawable/progressbar_indeterminate2" android:duration="200" />
<item android:drawable="@drawable/progressbar_indeterminate3" android:duration="200" />
</animation-list>把这些文件复制到自己工程下的drawable,就可以随心所欲的修改这些属性了,渐变,圆角等等
接下来只需要把改好的样式将原来的修改就可以了
<style name="mProgressBar" parent="@android:style/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">5dip</item>
<item name="android:maxHeight">5dip</item>
</style>应用时候
<ProgressBar
android:id="@+id/progressbar"
style="@style/mProgressBar"/>
本文介绍如何自定义Android系统的ProgressBar样式,包括替换默认样式的方法,并提供具体的XML配置示例。
900

被折叠的 条评论
为什么被折叠?



