用HTC的手机,装小米的系统。系统版本为2.3.7android。它的进度条没有全屏居中显示,并且自带橘红色的旋转圈圈,背景自带的为黑色。
解决方法如下:
pd = new ProgressDialog(context);
pd.setCanceledOnTouchOutside(false);
pd.setCancelable(true);
pd.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
context.finish();
}
});
pd.show();
pd.setContentView(R.layout.progress_bar); //自定义布局
pd.getWindow().setGravity(Gravity.CENTER); //进度条show()了之后,再调整居中显示
pd.getWindow().setBackgroundDrawableResource(R.color.transparent);//进度条show()了之后,再将背景设置为透明
progress_bar,自定义的布局。
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@color/transparent"
android:indeterminateDrawable="@drawable/progressbar" //规定进度条 形状以及颜色
>
</ProgressBar>
progressbar.xml 如下:
<?xml version="1.0" encoding="utf-8"?>
<animated-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.5"
android:shape="ring"
android:thicknessRatio="15"
android:useLevel="false" >
<gradient
android:centerColor="@color/font_gray" //灰色
android:centerY="0.50"
android:endColor="@color/font_darkgray" //灰色
android:startColor="@color/font_lightgray" //灰色
android:type="sweep"
android:angle="45"
android:useLevel="false" />
</shape>
</animated-rotate>
关于圈圈的形状,此处要求环的半径较大,环的厚度很薄。注意:
android:innerRadiusRatio 浮点型,以环的宽度比率来表示内环的半径,
例如,如果android:innerRadiusRatio,表示内环半径等于环的宽度除以5,这个值是可以被覆盖的,默认为9.
值越小,半径越大。
android:thicknessRatio 浮点型,以环的宽度比率来表示环的厚度,例如,如果android:thicknessRatio="2",
那么环的厚度就等于环的宽度除以2。这个值是可以被android:thickness覆盖的,默认值是3.
值越大,厚度越薄。
解决方法如下:
pd = new ProgressDialog(context);
pd.setCanceledOnTouchOutside(false);
pd.setCancelable(true);
pd.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
context.finish();
}
});
pd.show();
pd.setContentView(R.layout.progress_bar); //自定义布局
pd.getWindow().setGravity(Gravity.CENTER); //进度条show()了之后,再调整居中显示
pd.getWindow().setBackgroundDrawableResource(R.color.transparent);//进度条show()了之后,再将背景设置为透明
progress_bar,自定义的布局。
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@color/transparent"
android:indeterminateDrawable="@drawable/progressbar" //规定进度条 形状以及颜色
>
</ProgressBar>
progressbar.xml 如下:
<?xml version="1.0" encoding="utf-8"?>
<animated-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.5"
android:shape="ring"
android:thicknessRatio="15"
android:useLevel="false" >
<gradient
android:centerColor="@color/font_gray" //灰色
android:centerY="0.50"
android:endColor="@color/font_darkgray" //灰色
android:startColor="@color/font_lightgray" //灰色
android:type="sweep"
android:angle="45"
android:useLevel="false" />
</shape>
</animated-rotate>
关于圈圈的形状,此处要求环的半径较大,环的厚度很薄。注意:
android:innerRadiusRatio 浮点型,以环的宽度比率来表示内环的半径,
例如,如果android:innerRadiusRatio,表示内环半径等于环的宽度除以5,这个值是可以被覆盖的,默认为9.
值越小,半径越大。
android:thicknessRatio 浮点型,以环的宽度比率来表示环的厚度,例如,如果android:thicknessRatio="2",
那么环的厚度就等于环的宽度除以2。这个值是可以被android:thickness覆盖的,默认值是3.
值越大,厚度越薄。