android_自定义Loading框

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
public  class  CustomLoadingDialog  extends  Dialog {
 
     @ViewInject (R.id.custom_loading_dialog_indicator)
     private  ImageView indicatorIv;
     @ViewInject (R.id.custom_loading_dialog_message)
     private  TextView messageTv;
 
     private  CustomLoadingDialog(Context context,  int  theme) {
         super (context, theme);
     }
 
     public  static  CustomLoadingDialog createLoading(Context context) {
         CustomLoadingDialog dialog =  new  CustomLoadingDialog(context, R.style.CustomDialog);
         View content = LayoutInflater.from(context).inflate(
                 R.layout.custom_loading_dialog,  null );
         ViewUtils.inject(dialog, content);
         dialog.addContentView(content,  new  ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                 ViewGroup.LayoutParams.WRAP_CONTENT));
         return  dialog;
     }
 
     @Override
     public  void  onWindowFocusChanged( boolean  hasFocus) {
         if  (hasFocus) {
             indicatorIv.startAnimation(AnimationUtils.loadAnimation(
                     getContext(), R.anim.custom_loading_dialog));
         }
     }
 
     public  void  setMessage(String message) {
         if  (!TextUtils.isEmpty(message)) {
             messageTv.setVisibility(View.VISIBLE);
             messageTv.setText(message);
         else  {
             messageTv.setVisibility(View.GONE);
         }
     }
 
}

资源文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<style name= "CustomDialog"  parent= "@android:style/Theme.Dialog" >
         <item name= "android:windowFrame" > @null </item>
         <item name= "android:windowBackground" > @android :color/transparent</item>
         <!-- 边框 -->
         <item name= "android:windowIsFloating" > true </item>
         <!-- 是否浮现在activity之上 -->
         <item name= "android:windowNoTitle" > true </item>
         <!-- 无标题 -->
         <item name= "android:windowIsTranslucent" > true </item>
         <!-- 半透明 -->
         <item name= "android:backgroundDimEnabled" > true </item>
         <!-- 模糊 -->
     </style>
     
     <LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android"
     style= "@style/CustomDialogBackground"
     android:minWidth= "240dp"
     android:padding= "@dimen/Xlarge"
     >
 
     <ImageView
         android:id= "@+id/custom_loading_dialog_indicator"
         android:layout_width= "wrap_content"
         android:layout_height= "wrap_content"
         android:src= "@drawable/loading_indicator" />
 
     <TextView
         android:id= "@+id/custom_loading_dialog_message"
         android:layout_width= "wrap_content"
         android:layout_height= "wrap_content"
         android:visibility= "gone"
         android:layout_marginTop= "@dimen/medium"
         android:singleLine= "true"
         android:maxWidth= "200dp"
         android:textColor= "@android:color/black"
         android:textSize= "@dimen/text_noraml" />
</LinearLayout>
 
<set xmlns:android= "http://schemas.android.com/apk/res/android"
     android:shareInterpolator= "false" >
 
     <rotate
         android:interpolator= "@android:anim/linear_interpolator"
         android:pivotX= "50%"
         android:pivotY= "50%"
         android:fromDegrees= "0"
         android:toDegrees= "360"
         android:duration= "1500"
         android:startOffset= "-1"
         android:repeatMode= "restart"
         android:repeatCount= "-1" />
 
</set>

使用
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public  void  showLoadingDialog() {
         if  (loadingDialog ==  null ) {
             loadingDialog = CustomLoadingDialog.createLoading( this );
         }
         loadingDialog.setMessage(getResources().getString(R.string.loading_message_default));
         loadingDialog.show();
     }
 
     public  void  showLoadingDialog(String message) {
         if  (loadingDialog ==  null ) {
             loadingDialog = CustomLoadingDialog.createLoading( this );
         }
         if  (!TextUtils.isEmpty(message)) {
             loadingDialog.setMessage(message);
         else  {
             loadingDialog.setMessage(getResources().getString(R.string.loading_message_default));
         }
         loadingDialog.show();
     }
 
     public  void  hideLoadingDialog() {
         if  (loadingDialog !=  null  && loadingDialog.isShowing()) {
             loadingDialog.dismiss();
         }
     }
 
     public  void  setLoadingDialogCancel( boolean  canCancel) {
         loadingDialog.setCancelable(canCancel);
     }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值