dialog形式的activity屏幕触摸事件总结
2017-01-04 21:56
330 查看
Dialog大家都在项目中会用到,前两天在项目中我们要弹出一个Activity形式的dialog,大家都知道dialog本身提供了触摸屏幕事件:
比如说dialog的setCanceledOnTouchOutside方法,而弹出一个activity形式的dialog如何去设置呢?
首先我们看下dialog:
大家要注意。关于dialog大家在熟悉不过,这里不做 过多的说明。
有关于弹出来一个Theme形式的activity,如何实现向dialog一样点击屏幕不消失呢?
这里需要在activity的方法里写入两个标识:
而第二个则是:
如果你觉得此文对您有所帮助,欢迎入群 QQ交流群 :232203809
微信公众号:终端研发部
(欢迎关注学习和交流)
比如说dialog的setCanceledOnTouchOutside方法,而弹出一个activity形式的dialog如何去设置呢?
首先我们看下dialog:
/** * Sets whether this dialog is canceled when touched outside the window's * bounds OR pressed the back key. If setting to true, the dialog is * set to be cancelable if not * already set. * * @param cancel Whether the dialog should be canceled when touched outside * the window OR pressed the back key. */ public MaterialDialog setCanceledOnTouchOutside(boolean cancel) { this.mCancel = cancel; if (mBuilder != null) { mBuilder.setCanceledOnTouchOutside(mCancel); } return this; }大概意思就是:大概意思就是当初莫屏幕外会点击返回键的时候dialog是否可以关闭,如果设置true,可以取消,点击返回键可以关闭 掉。对于部分4.0手机可能不起作用。
大家要注意。关于dialog大家在熟悉不过,这里不做 过多的说明。
有关于弹出来一个Theme形式的activity,如何实现向dialog一样点击屏幕不消失呢?
这里需要在activity的方法里写入两个标识:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //getWindow().setFlags(WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH); getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); initVoidData(); init(); }其中:
/** Window flag: even when this window is focusable (its * {@link #FLAG_NOT_FOCUSABLE} is not set), allow any pointer events * outside of the window to be sent to the windows behind it. Otherwise * it will consume all pointer events itself, regardless of whether they * are inside of the window. */ public static final int FLAG_NOT_TOUCH_MODAL = 0x00000020;WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL大体意思是用于窗口标志位的表示,将消耗触摸事件,进行行向下传递。
而第二个则是:
/** Window flag: if you have set {@link #FLAG_NOT_TOUCH_MODAL}, you * can set this flag to receive a single special MotionEvent with * the action * {@link MotionEvent#ACTION_OUTSIDE MotionEvent.ACTION_OUTSIDE} for * touches that occur outside of your window. Note that you will not * receive the full down/move/up gesture, only the location of the * first down as an ACTION_OUTSIDE. */ public static final int FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000;大体意思是如果你设置了这个标识,则你可以通过这个标识接收一个特殊的动作,触摸发生在你的窗口之外。 注意,你不会接收完整的向下/移动/向上手势,只有位置第一次作为ACTION_OUTSIDE。此时触摸事件向下传递。
如果你觉得此文对您有所帮助,欢迎入群 QQ交流群 :232203809
微信公众号:终端研发部
(欢迎关注学习和交流)
相关文章推荐
- 面试题
- Linux下的权限管理
- androidstudio中外部数据库的导入
- javascript的入门概要
- 64. Minimum Path Sum
- 10、开链法解决散列表保存字典的碰撞问题
- redis事务
- 等差数列前n项和
- cmd 快捷操作
- 更容易理解 有根树的同构 无根树的同构
- 每天一个python模块之Requests
- 去除代码中的注释(二) 实现 上
- 计算字符串最后一个单词的长度
- 并查集算法详解
- 树之存储结构
- -jar参数运行应用时classpath的设置方法
- 记负均正
- 做web开发和测试,修改hosts指定某个域名访问某个特定的IP后,如何使hosts立即生效的方法
- java内部类
- ip地址定位