android 自定义progressdialog
在开发过程中需要自定义一个progressdialog来优化界面,为此随手写一个类似的程序。大致效果如下:
点击按钮,progressdialog转动。

package com.test.app;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class ProgressActivity extends Activity {
/** Called when the activity is first created. */
private Button button;
private ProgressDialog dialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button)findViewById(R.id.btn);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
dialog = new ProgressDialog(ProgressActivity.this);
dialog.setIndeterminate(true);
dialog.setCancelable(true);
dialog.show();
dialog.setContentView(R.layout.my_progress);//这边一定要在后面
}
});
}
}
R.layout.my_progress
<?xml version="1.0" encoding="utf-8"?> <ProgressBar xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:indeterminateDrawable="@drawable/myprogress_style" />
myprogress_style
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0" android:toDegrees="360"> <shape android:shape="ring" android:innerRadiusRatio="3" android:thicknessRatio="8" android:useLevel="false"> <gradient android:type="sweep" android:useLevel="false" android:startColor="#FFFFFF" android:centerColor="#FFCC35" android:centerY="0.50" android:endColor="#CE0000" /> </shape> </rotate>
颜色可以自定义,上述,是自己写着玩的。

浙公网安备 33010602011771号