标签:
最近做项目的时候,做检查更新功能,需要做一个notification的下载进度,就需要使用progressBar控件,本来打算使用自定义的继承自ProgressBar,结果发现不能用,谷歌限制了只能使用特定的系统的progressBar,所以不得自定义样式了。 
在xml中使用方式: 
可以使用系统的样式
   <ProgressBar
            android:id="@+id/progressBar"
            style="?android:progressBarStyleHorizontal"
            android:progress="10"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="3dp" />或者
        <ProgressBar
            android:id="@+id/progressBar"
            style="@android:style/Widget.ProgressBar.Horizontal"
            android:progress="10"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="3dp" />系统自带的样式 
 
系统自带的样式 
 
看看系统是如何定义样式的
    <style name="Widget.ProgressBar.Horizontal">
        <item name="indeterminateOnly">false</item>
        <item name="progressDrawable">@drawable/progress_horizontal</item>
        <item name="indeterminateDrawable">@drawable/progress_indeterminate_horizontal</item>
        <item name="minHeight">20dip</item>
        <item name="maxHeight">20dip</item>
        <item name="mirrorForRtl">true</item>
    </style>发现主要是下面的代码来实现bar的样式
        <item name="progressDrawable">@drawable/progress_horizontal</item>我们自定义这部分代码实现
<?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="@color/statusbar_bg"
                    android:centerColor="@color/statusbar_bg"
                    android:centerY="0.75"
                    android:endColor="@color/statusbar_bg"
                    android:angle="270"
                    />
            </shape>
        </clip>
    </item>
    <!--进度条-->
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="5dip" />
                <gradient
                    android:startColor="@color/statusbar_bg"
                    android:centerColor="@color/statusbar_bg"
                    android:centerY="0.75"
                    android:endColor="@color/statusbar_bg"
                    android:angle="270"
                    />
            </shape>
        </clip>
    </item>
</layer-list>使用啥的就不说了,下面看看圆形进度条 
同样的方式:
    <style name="Widget.ProgressBar.Small">
        <item name="indeterminateDrawable">@drawable/progress_small_white</item>
        <item name="minWidth">16dip</item>
        <item name="maxWidth">16dip</item>
        <item name="minHeight">16dip</item>
        <item name="maxHeight">16dip</item>
    </style>可以看出下面这行代码就是实现了
      <item name="indeterminateDrawable">@drawable/progress_small_white</item>    <style name="mProgress_circle">
        <item name="indeterminateDrawable">@drawable/ykt_loading</item>
        <item name="minWidth">16dip</item>
        <item name="maxWidth">16dip</item>
        <item name="minHeight">16dip</item>
        <item name="maxHeight">16dip</item>
    </style>标签:
原文地址:http://blog.csdn.net/u011625768/article/details/51352485