android圓形進度條ProgressBar顏色設定
阿新 • • 發佈:2018-12-31
Java程式碼
Java程式碼
來自: http://407827531.iteye.com/blog/1067025
預設情況下Indeterminate Progressbar是白色的,如果容器的背景也是白色的,這樣就根本看不到Progressbar了。
幸好Android自帶了一些反轉樣式,你可以採用其中一個合適的:
Java程式碼
Java程式碼
定義res/anim/loading.xml如下:
Java程式碼
Java程式碼
定義res/drawable/dialog_style_xml_color.xml如下:
Java程式碼
Java程式碼
定義res/drawable/dialog_style_xml_icon.xml如下:
Java程式碼
Java程式碼
Java程式碼
Java程式碼
- <ProgressBar
- android:id="@+id/loadProgressBar"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:indeterminateDrawable="@drawable/progressbar" />
Java程式碼
- <?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>
來自:
預設情況下Indeterminate Progressbar是白色的,如果容器的背景也是白色的,這樣就根本看不到Progressbar了。
幸好Android自帶了一些反轉樣式,你可以採用其中一個合適的:
Java程式碼
- <ProgressBar style="@android:style/Widget.ProgressBar.Inverse"/>
- <ProgressBar style="@android:style/Widget.ProgressBar.Large.Inverse"/>
- <ProgressBar style="@android:style/Widget.ProgressBar.Small.Inverse"/>
Java程式碼
- <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如下:
Java程式碼
- <?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>
Java程式碼
- <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如下:
Java程式碼
- <?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>
Java程式碼
- <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如下:
Java程式碼
- <?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>
Java程式碼
- <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" />
Java程式碼
- <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>
Java程式碼
- mProgress = (ProgressBar) findViewById(R.id.progress_bar);
- Drawable d = this.getResources().getDrawable(R.drawable.my_progress);
- mProgress.setProgressDrawable(d);