loading android

 drawal/loading.xml

<?xml version="1.0" encoding="utf-8"?>
<animated-rotate android:drawable="@drawable/share_popout_icon_loading" android:pivotX="50.0%" android:pivotY="50.0%"
  xmlns:android="http://schemas.android.com/apk/res/android" />

、、-------------------------------------------------------------

总觉的自带的progressdialog很丑,所以为了让自己看着舒服一些,不得以就得自己定义样式了,自定义Progressdialog其实很简单,一个layout文件,一个shape文件

再来,然后再有一个资源文件就可以了。

        一下是代码

     自定义Progressdialog布局文件

 

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:background="@drawable/bg_dialog_shape"  
  6.     android:gravity="center" >  
  7.   
  8.     <LinearLayout  
  9.         android:layout_width="wrap_content"  
  10.         android:layout_height="wrap_content"  
  11.         android:layout_gravity="center"  
  12.         android:gravity="center_horizontal"  
  13.         android:orientation="vertical" >  
  14.   
  15.         <ProgressBar  
  16.             android:id="@+id/oahprogressbar"  
  17.             style="@android:style/Widget.ProgressBar.Small"  
  18.             android:layout_width="30dip"  
  19.             android:layout_height="30dip"  
  20.             android:indeterminateDrawable="@drawable/progress" />  
  21.   
  22.         <TextView  
  23.             android:id="@+id/oaprogresstitle"  
  24.             android:layout_width="wrap_content"  
  25.             android:layout_height="wrap_content"  
  26.             android:layout_marginTop="20dip"  
  27.             android:gravity="center_vertical"  
  28.             android:text="正在验证..."  
  29.             android:textColor="@color/white" />  
  30.     </LinearLayout>  
  31.   
  32. </FrameLayout>  

ProgressBar 

  1. indeterminateDrawable的属性  
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <rotate xmlns:android="http://schemas.android.com/apk/res/android" >  
  3.     <rotate xmlns:android="http://schemas.android.com/apk/res/android"       
  4.     android:drawable="@drawable/loading" <!--这就是一张图片,不需要每一个状态一张图片-->  
  5.     android:pivotX="50%"       
  6.     android:pivotY="50%" />  
  7.   
  8. </rotate>  



重写ProgressDialog ,

 

 

  1. package com.zl.dialog.view;  
  2.   
  3. import com.zl.payslip.R;  
  4.   
  5. import android.app.Dialog;  
  6. import android.app.ProgressDialog;  
  7. import android.content.Context;  
  8. import android.os.Bundle;  
  9.   
  10. /** 
  11.  * @author gqs 
  12.  * @version 创建时间:2012-11-23 上午10:59:43 
  13.  * 类说明 
  14.  */  
  15. public class MyDialog  extends ProgressDialog{  
  16.   
  17.     public PaySlipDialog(Context context, int theme) {  
  18.         super(context, theme);  
  19.         // TODO dvsdfads  
  20.     }  
  21.   
  22.     public PaySlipDialog(Context context) {  
  23.         super(context);  
  24.         // TODO sdfsdf  
  25.           
  26.     }  
  27.     @Override  
  28.     protected void onCreate(Bundle savedInstanceState) {  
  29.         // TODO Auto-generated method stub  
  30.         super.onCreate(savedInstanceState);  
  31.           
  32. //      progressDialog.setIndeterminate(true);  
  33.         setCancelable(false);  
  34.   
  35.         //progressDialog.show()  
  36.         setContentView(R.layout.progressdialog_layout);  
  37.           
  38.     }  
  39.     public void showDialog()  
  40.     {  
  41.         show();  
  42.     }  
  43. }  


 

最后在Acivity里面直接调用就行了

public void showDialog(Context context)

{

        

MyDialog dialog = new MyDialog(context);

dialog.showDialog();

}

原文地址:https://www.cnblogs.com/fx2008/p/3141386.html