老式水平样式(比较粗)
style=
"@android:style/Widget.ProgressBar.Horizontal"
新式水平样式(比较美观)
style=
"?android:attr/progressBarStyleHorizontal"
老式水平样式(颜色)改变:
@android:style/Widget.ProgressBar.Horizontal
--->
<item
name=
"progressDrawable"
>
@drawable/progress_horizontal
</item>
--->
<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>
//应用
<ProgressBar
android
:layout_marginTop=
"10dp"
android
:layout_width=
"match_parent"
android
:layout_height=
"wrap_content"
style=
"@android:style/Widget.ProgressBar.Horizontal"
android
:progressDrawable=
"@drawable/xin_styleprogressbar_layout"
android
:max=
"100"
android
:progress=
"30"
android
:secondaryProgress=
"60"
android
:maxHeight=
"3dp"
android
:minHeight=
"3dp"
/>
老式水平样式改变:
@android:style/Widget.ProgressBar.Horizontal
--->
<item
name=
"progressDrawable"
>
@drawable/progress_horizontal
</item>
--->
<layer-list
xmlns:
android
=
"http://schemas.android.com/apk/res/android"
>
<item
android
:id=
"@android:id/background"
android
:drawable=
"@drawable/android_1512_background"
/>
<item
android
:id=
"@android:id/progress"
android
:drawable=
"@drawable/android_1512_font"
/>
</layer-list>
在代码中追加:
ProgressBar
bar
;
Handler
handler
=
new
Handler(){
@Override
public void
handleMessage
(Message msg) {
if
(
bar
.getProgress() ==
100
){
bar
.setProgress(
0
)
;
}
else
{
bar
.setProgress(
bar
.getProgress()+
1
)
;
}
handler
.sendEmptyMessageDelayed(
0
,
100
)
;
}
}
;
@Override
protected void
onCreate
(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState)
;
setContentView(R.layout.
activity_main
)
;
bar
= (ProgressBar) findViewById(R.id.
mypb
)
;
handler
.sendEmptyMessage(
0
)
;
}
//应用:
<ProgressBar
android
:layout_marginTop=
"10dp"
android
:layout_width=
"300dp"
android
:layout_height=
"96dp"
style=
"@android:style/Widget.ProgressBar.Horizontal"
android
:progressDrawable=
"@drawable/newstyle"
android
:max=
"100"
android
:id=
"@+id/mypb"
/>
默认样式
style=
"@android:style/Widget.ProgressBar"
更改:
style=
"@android:style/Widget.ProgressBar"
--->
//该文件在F:\adt\adt-bundle-windows-x86_64-20140702\sdk\platforms\android-20\data\res\drawable中打开
<item
name=
"indeterminateDrawable"
>
@drawable/progress_medium_white
</item>
如下:
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/spinner_white_48"
android:pivotX="50%"
android:pivotY="50%"
android:framesCount="12"
android:frameDuration="100" />
将 android:drawable改为自定义图片
--->
<rotate
xmlns:
android
=
"http://schemas.android.com/apk/res/android"
android
:drawable=
"@drawable/loading_32dp"
android
:pivotX=
"50%"
android
:pivotY=
"50%"
/>
//应用
<ProgressBar
android
:layout_marginTop=
"10dp"
android
:layout_width=
"match_parent"
android
:layout_height=
"wrap_content"
style=
"@android:style/Widget.ProgressBar"
android
:indeterminateDrawable=
"@drawable/circle_layout"
android
:indeterminateDuration=
"1000"
/>
最终效果图: