Dialog 自定义使用2(进度条)
1: 自定义的Dialog 代码:
public class IphoneProgersssDialog extends Dialog { private Context context; private ImageView img; private TextView txt; public IphoneProgersssDialog(Context context) { super(context, R.style.iphone_progress_dialog); this.context=context; //加载布局文件 LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view=inflater.inflate(R.layout.iphone_progress_dialog, null); img=(ImageView) view.findViewById(R.id.iphone_progress_dialog_img); // 进度图片 txt=(TextView) view.findViewById(R.id.iphone_progress_dialog_txt); //给图片添加动态效果 Animation anim=AnimationUtils.loadAnimation(context, R.anim.progressbar); img.setAnimation(anim); // 变成旋转 txt.setText(R.string.iphone_progressbar_dialog_txt); //dialog添加视图 setContentView(view); } public void setMsg(String msg){ //进度提示消息 txt.setText(msg); } public void setMsg(int msgId){ txt.setText(msgId); } }
2 ,dialog定义样式
<style name="iphone_progress_dialog" parent="@android:style/Theme.Dialog"> //构造方法中 <item name="android:windowFrame">@null</item> <!--Dialog的windowFrame框为无 --> <item name="android:windowIsFloating">true</item><!-- 是否漂现在activity上 --> <item name="android:windowIsTranslucent">true</item><!-- 是否半透明 --> <item name="android:windowNoTitle">true</item> <item name="android:backgroundDimEnabled">false</item> //模糊 <item name="android:windowBackground">@drawable/load_bg</item> //dialog背景 </style>
3.定义动画文件 progressbar.xml
<?xml version="1.0" encoding="utf-8"?> <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="1000" android:startOffset="-1" android:repeatMode="restart" android:repeatCount="-1"/> </set>