Android 自定义ProgressDialog

原文   http://blog.sina.com.cn/s/blog_3e333c4a01012en2.html


Android 自定义ProgressDialog_第1张图片

//自定义  my_progress.xml 在drawable中
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"       
      android:drawable="@drawable/refresh" //转圈的图标
      android:pivotX="50%"       
      android:pivotY="50%" />

// 自定义  customprogress.xml 在layout中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:orientation="vertical"
   android:gravity="center"> 
   <ProgressBar 
android:id="@+id/oahprogressbar"
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:indeterminateDrawable=" @drawable/my_progress"
/>
   <TextView
   android:layout_width="wrap_content"
   android:layout_height="fill_parent" android:text="load..."
   android:id="@+id/oaprogresstitle" android:textColor="@color/milk"
   android:gravity="center_vertical"
   />
</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);
}
}

你可能感兴趣的:(java,android,layout,Class,dialog,encoding)