原文 http://blog.sina.com.cn/s/blog_3e333c4a01012en2.html
//自定义
my_progress.xml 在drawable中
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
// 自定义
customprogress.xml 在layout中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/oahprogressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateDrawable="
@drawable/my_progress"
/>
</LinearLayout>
******************* java 代码 ******************************************
ProgressDialog progressdialog ;
//创建dialog
@Override
protected Dialog onCreateDialog(int id) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
switch (id) {
case 1: {
progressdialog = new ProgressDialog(this);
progressdialog.setMessage(message);
progressdialog.setIndeterminate(true);
progressdialog.setCancelable(cancel);
return progressdialog;
}
}
return null;
}
//调用
class AffairTask extends AsyncTask<Void, Void, Boolean> {
protected void onPreExecute() {
showDialog(1);
progressdialog.setContentView(
R.layout.customprogress);//一定要写在showDialog()之后,否则抛异常
}
@Override
protected Boolean doInBackground(Void... params) {
}
@Override
protected void onPostExecute(Boolean result) {
removeDialog(1);
}
}