ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码
当前位置:首页 >> 低调看直播体育app软件下载 >> Android开发 >> 安卓 自定义AlertDialog对话框加载提示框

安卓 自定义AlertDialog对话框加载提示框

来源:网络整理     时间:2016-06-27     关键词:

本篇文章主要介绍了" 安卓 自定义AlertDialog对话框加载提示框",主要涉及到方面的内容,对于Android开发感兴趣的同学可以参考一下: AlertDialog有以下六种使用方法:一、简单的AlertDialog(只显示一段简单的信息)二、带按钮的AlertDialog(显示提示信息,让用户操作)...

AlertDialog有以下六种使用方法:

一、简单的AlertDialog(只显示一段简单的信息)

二、带按钮的AlertDialog(显示提示信息,让用户操作)

三、类似ListView的AlertDialog(展示内容)

四、类似RadioButton的AlertDialog(让用户选择,单选)

五、类似CheckBox的AlertDialog(让用户多选)

六、自定义View的AlertDialog(当以上方式满足不了你的需求,就要自定义了)

这里写的就是第六种用法,效果图如下(效果类似与IOS中的MBProgressHUD)

 安卓 自定义AlertDialog对话框加载提示框

具体实现如下:

.java代码
// 自定义弹出框,框内放入图片,图片设置旋转动画
AlertDialog alert_progress = new AlertDialog.Builder(当前activity.this).create();
alert_progress.show();
alert_progress.setCancelable(false); // 点击背景时对话框不会消失
// alert_progress.dismiss(); // 取消对话框
Window window = alert_progress.getWindow();
window.setContentView(R.layout.alert_dialog_progress_view); //加载自定义的布局文件
WindowManager.LayoutParams wm = window.getAttributes();
wm.width = 250; // 设置对话框的宽
wm.height = 200; // 设置对话框的高
wm.alpha = 0.5f; // 对话框背景透明度
wm.dimAmount = 0.6f; // 遮罩层亮度
window.setAttributes(wm);
ImageView img = (ImageView)window.findViewById(R.id.progress_bar); // 获取布局文件中的ImageView控件
img.setBackgroundResource(R.drawable.loading_one); // 设置图片,也可在布局文件中设置
// 设置旋转动画
Animation tranfrom = new RotateAnimation(0,359,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);(359:旋转角度(可自调),若为360会有卡顿,正数为顺势针旋转,负数为逆时针)
tranfrom.setDuration(2000); // 旋转速度
tranfrom.setFillAfter(true);
tranfrom.setRepeatCount(-1); // -1为一只旋转,若10,则旋转10次设定的角度后停止
// tranfrom.cancel(); // 取消动画
img.setAnimation(tranfrom);

布局代码:


android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBlack">
<>
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<>
android:text="正在加载..."
android:layout_width="match_parent"
android:layout_height="20dp"
android:textColor="@color/colorWhite"
android:layout_gravity="center"
android:gravity="center"/>

附:旋转背景图

 安卓 自定义AlertDialog对话框加载提示框

以上就介绍了 安卓 自定义AlertDialog对话框加载提示框,包括了方面的内容,希望对Android开发有兴趣的朋友有所帮助。

本文网址链接:http://www.codes51.com/article/detail_2110531.html

相关图片

相关文章