PopupWindow和AlertDialog区别
来源:互联网 发布:宁夏网络干部培训 编辑:程序博客网 时间:2024/05/21 18:21
区别如下:
1. AlertDialog是非阻塞线程的,AlertDialog弹出的时候,后台可是还可以做其他事情
PopupWindow是阻塞线程的,PopupWindow弹出时,程序会等待,在PopupWindow退出前,程序一直等待,
只有当我们调用了dismiss方法的后,PopupWindow退出,程序才会向下执行。
2.AlertDialog的位置固定
setIcon :为对话框设置图标
setMessage:为对话框设置内容
setView : 给对话框设置自定义样式
setItems :设置对话框要显示的一个list,一般用于显示几个命令时
setMultiChoiceItems :用来设置对话框显示一系列的复选框
setNeutralButton :普通按钮
setNegativeButton :对话框添加"No"按钮
create : 创建对话框
show :显示对话框
setTitle("对话框的标题").
setMessage("对话框的内容").
示例:
new AlertDialog.Builder(MainActivity.this).setTitle("简易对话框").setMessage("对话框文本").setPositiveButton("确定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {/** 第一个参数:上下文对象。可用getApplicationContext()或当前Activity.this* 第二个参数:要显示的字符串* 第三个参数:显示时间的长短。Toast有默认的两个LENGTH_SHORT(短)和LENGTH_LONG(长),也可以使用毫秒2000ms* */Toast.makeText(MainActivity.this,"按了确定按钮",Toast.LENGTH_SHORT).show();}}).setNegativeButton("取消", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {Toast.makeText(MainActivity.this,"按了取消按钮",Toast.LENGTH_SHORT).show();}}).show();
PopupWindow的位置按照有无偏移分,可以分为偏移和无偏移两种;按照参照物的不同,可以分为相对于某个控件
(Anchor锚)和相对于父控件。具体如下
showAsDropDown(View anchor):相对某个控件的位置(正左下方),无偏移
showAsDropDown(View anchor, int xoff, int yoff):相对某个控件的位置,有偏移
showAtLocation(View parent, int gravity, int x, int y):相对于父控件的位置(例如正中央Gravity.CENTER,
下方Gravity.BOTTOM等),可以设置偏移或无偏移
LayoutInflater layoutInflater = LayoutInflater.from(this);
View popupWindow = layoutInflater.inflate(R.layout.popup, null);
PopupWindow示例:
Android PopupWindow详解
0 0
- PopupWindow和AlertDialog区别
- PopupWindow和AlertDialog区别
- PopupWindow和AlertDialog区别
- PopupWindow和AlertDialog区别
- PopupWindow和AlertDialog区别
- PopupWindow和AlertDialog区别
- android PopupWindow和AlertDialog区别
- PopupWindow和AlertDialog的区别
- PopupWindow和AlertDialog的使用和区别
- Android AlertDialog和PopupWindow使用和区别
- PopupWindow与AlertDialog区别
- 自定义PopupWindow和AlertDialog
- Android的对话框有两种:PopupWindow和AlertDialog区别
- popupWindow的创建和与alertDialog的区别
- AlertDialog 与 PopupWindow的 区别
- android 中popupWindow与AlertDialog区别
- PopupWindow,AlertDialog
- Android PopupWindow和AlertDialog学习笔记
- 如何实现多行文字垂直居中
- 第十四周项目2-二叉树排序树中查找的路径
- C语言非递归实现二叉树的先序、中序、后序、层序遍历
- 33. Search in Rotated Sorted Array&81. Search in Rotated Sorted Array II
- java微信 客服接口-发消息 中文乱码
- PopupWindow和AlertDialog区别
- 第十四周项目2-二叉树排序树中查找的路径
- HTML5清除默认格式代码
- hashset实现原理
- 十一周项目一 验证算法二查数算法的验证
- 解决Spring AOP 事务 配置 失效原因--业务类里抛出的异常不满足事务拦截器里定义的异常
- 第5章 Spring Boot基础
- 打造扛得住的MYSQL数据库架构
- Android M动态申请获取权限android.permission.READ_PHONE_STATE