进度条布局xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:id="@+id/progress_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:background="@anim/progress_indeterminate_horizontal"/>
<TextView
android:id="@+id/progress_textview"
android:text="@string/loading"
android:textColor="#ffffff"
android:textSize="17sp"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
/**
* 自定义进度条
* Created by Lezg on 2014/5/2.
*/
public class MyProgressDialog extends Dialog{
private static MyProgressDialog myProgressDialog = null;
private MyProgressDialog(Context context, int theme){
super(context, theme);
}
public static MyProgressDialog createDialog(Context context){
myProgressDialog = new MyProgressDialog(context, R.style.customProgressDialog);
myProgressDialog.setContentView(R.layout.progress_dialog);
myProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;
return myProgressDialog;
}
public void onWindowFocusChanged(boolean hasFocus){
if(myProgressDialog == null){
return;
}
ImageView imageView = (ImageView)myProgressDialog.findViewById(R.id.progress_image);
AnimationDrawable ad = (AnimationDrawable)imageView.getBackground();
if(ad != null){
ad.start();
}
}
/* public MyProgressDialog setMessage(String msg){
TextView tvMsg = (TextView)myProgressDialog.findViewById(R.id.progress_textview);
if(tvMsg != null){
tvMsg.setText(msg);
}
return myProgressDialog;
}*/
}