dialog_background_style.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <shape xmlns:android="http://schemas.android.com/apk/res/android" > 3 4 <solid android:color="#33000000" /> 5 6 <corners android:radius="10dp" /> 7 8 </shape>
anim_dialog.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <set xmlns:android="http://schemas.android.com/apk/res/android" 3 android:shareInterpolator="false" > 4 5 <rotate 6 android:duration="1500" 7 android:fromDegrees="0" 8 android:interpolator="@android:anim/linear_interpolator" 9 android:pivotX="50%" 10 android:pivotY="50%" 11 android:repeatCount="-1" 12 android:repeatMode="restart" 13 android:startOffset="-1" 14 android:toDegrees="+360" /> 15 16 </set>
在styles.xml中定义如下主题:
1 <style name="loading_dialog" parent="android:style/Theme.Dialog"> 2 <item name="android:windowFrame">@null</item> 3 <item name="android:windowNoTitle">true</item> 4 <item name="android:windowIsFloating">true</item> 5 <item name="android:windowBackground">@drawable/dialog_background_style</item> 6 </style>
代码实现:
1 package com.wangzhen.view; 2 3 import com.wangzhen.bottomwindow.R; 4 5 import android.app.Dialog; 6 import android.content.Context; 7 import android.os.Bundle; 8 import android.view.LayoutInflater; 9 import android.view.View; 10 import android.view.animation.Animation; 11 import android.view.animation.AnimationUtils; 12 import android.widget.ImageView; 13 14 public class MyProgressDialog extends Dialog { 15 private Context mContext; 16 private LayoutInflater mInflater; 17 18 public MyProgressDialog(Context context) { 19 super(context, R.style.loading_dialog); 20 mContext = context; 21 mInflater = LayoutInflater.from(mContext); 22 } 23 24 @Override 25 protected void onCreate(Bundle savedInstanceState) { 26 super.onCreate(savedInstanceState); 27 View view = mInflater.inflate(R.layout.mydialog_layout, null); 28 ImageView ImageView_Icon = (ImageView) view 29 .findViewById(R.id.ImageView_Icon); 30 // 为ImageView添加动画 31 Animation animation = AnimationUtils.loadAnimation(mContext, 32 R.anim.anim_dialog); 33 ImageView_Icon.startAnimation(animation); 34 setContentView(view); 35 } 36 37 }