天天看點

android圓形進度條ProgressBar顔色設定

花樣android Progressbar http://www.eoeandroid.com/thread-1081-1-1.html

http://www.cnblogs.com/xirihanlin/archive/2010/06/14/1758145.html

xml布局檔案需加入如下的進度條構件:

<ProgressBar
        android:id="@+id/loadProgressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminateDrawable="@drawable/progressbar" />
           

其中的indeterminteDrawable屬性就是用來設定進度條顔色等屬性的,其内容如下:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360" >

    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="8"
        android:useLevel="false" >

        <gradient
            android:centerColor="#FFFFFF"
            android:centerY="0.50"
            android:endColor="#FFFF00"
            android:startColor="#000000"
            android:type="sweep"
            android:useLevel="false" />
    </shape>

</rotate>
           

參考:http://dev.10086.cn/cmdn/bbs/viewthread.php?tid=18469

http://tienfook.blog.163.com/blog/static/1666620112010528637217/

http://www.ihoton.com/androidandroid-progressbar-color.html

三種方式實作自定義圓形頁面加載中效果的進度條:

來自:http://407827531.iteye.com/blog/1067025

預設情況下Indeterminate Progressbar是白色的,如果容器的背景也是白色的,這樣就根本看不到Progressbar了。

幸好Android自帶了一些反轉樣式,你可以采用其中一個合适的:

<ProgressBar style="@android:style/Widget.ProgressBar.Inverse"/> 
<ProgressBar style="@android:style/Widget.ProgressBar.Large.Inverse"/> 
<ProgressBar style="@android:style/Widget.ProgressBar.Small.Inverse"/>
           

進度條:

<ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
<ProgressBar
        android:id="@+id/circleProgressBar"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        mce_style="?android:attr/progressBarStyleLarge" />
           

一、通過動畫實作

定義res/anim/loading.xml如下:

<?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/loading_01"
        android:duration="150"/>

    <item
        android:drawable="@drawable/loading_02"
        android:duration="150"/>

    <item
        android:drawable="@drawable/loading_03"
        android:duration="150"/>

    <item
        android:drawable="@drawable/loading_04"
        android:duration="150"/>

    <item
        android:drawable="@drawable/loading_05"
        android:duration="150"/>

    <item
        android:drawable="@drawable/loading_06"
        android:duration="150"/>

    <item
        android:drawable="@drawable/loading_07"
        android:duration="150"/>

</animation-list>
           

在layout檔案中引用如下:

<ProgressBar
        android:id="@+id/loading_process_dialog_progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="false"
        android:indeterminateDrawable="@anim/loading" />
           

二、通過自定義顔色實作

定義res/drawable/dialog_style_xml_color.xml如下:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360" >

    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="8"
        android:useLevel="false" >

        <gradient
            android:centerColor="#FFDC35"
            android:centerY="0.50"
            android:endColor="#CE0000"
            android:startColor="#FFFFFF"
            android:type="sweep"
            android:useLevel="false" />
    </shape>

</rotate>
           

在layout檔案中引用如下:

<ProgressBar
        android:id="@+id/loading_process_dialog_progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="false"
        android:indeterminateDrawable="@drawable/dialog_style_xml_color" />
           

三、使用一張圖檔進行自定義

定義res/drawable/dialog_style_xml_icon.xml如下:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <rotate
            android:drawable="@drawable/dialog_progress_round"
            android:fromDegrees="0.0"
            android:pivotX="50.0%"
            android:pivotY="50.0%"
            android:toDegrees="360.0" />
    </item>

</layer-list>
           

在layout檔案中引用如下:

<ProgressBar
        android:id="@+id/loading_process_dialog_progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="false"
        android:indeterminateDrawable="@drawable/dialog_style_xml_icon" />
           

或者

<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="@color/progress_start"   
                android:endColor="@color/progress_end"   
                android:angle="270" />   
        </shape>   
    </clip>   
</item> 
</layer-list>
           

代碼中設定:

mProgress = (ProgressBar) findViewById(R.id.progress_bar);
		Drawable d = this.getResources().getDrawable(R.drawable.my_progress);
		mProgress.setProgressDrawable(d);