关于 PopupWindow 响应 Back 按键收起
2016-07-15 13:52
363 查看
项目中遇到一个Bug:PopupWindow 不响应 Back 键收回了。
google了一下,发现解决方法是:PopupWindow#setBackgroundDrawable(new BitmapDrawable())
具体原因是:
The reason the background cannot be null is because of what happens in
翻译一下就是:在
google了一下,发现解决方法是:PopupWindow#setBackgroundDrawable(new BitmapDrawable())
具体原因是:
The reason the background cannot be null is because of what happens in
PopupWindow#preparePopup. If it detects
background != nullit creates an instance of
PopupViewContainerand calls
setBackgroundDrawableon that and puts your content view in it.
PopupViewContaineris basically a
FrameLayoutthat listens for touch events and the
KeyEvent.KEYCODE_BACKevent to dismiss the window. If background == null, it doesn't do any of that and just uses your content view. You can, as an alternative to depending on
PopupWindowto handle that, extend your root
ViewGroupto behave the way you want.
翻译一下就是:在
PopupWindow初始化的时候会监测是否设置了背景。如果已设置的话,会创建一个
PopupViewContainer(类似于 FrameLayout)来监听 Back 按键。但如果没有设置背景,就不会创建
PopupViewContainer,因此无监听。当然,也可以利用
PopupWindow的 root
ViewGroup 来处理监听。
相关文章推荐
- 90%成功提升用户回头率的网站优化技巧
- android系统架构图及各层介绍
- 使用爬虫抓取网站异步加载数据
- Centos 6 安装Docker
- MFC开发Opencv3.0打开文件夹选择图片进行检测
- 在linux下安装Qt3并配置环境变量后,make编译报错
- Hadoop之Pig
- Ganglia监控Hadoop与HBase集群
- Hadoop2.0集群、Hbase集群、Zookeeper集群、Hive工具、Sqoop工具、Flume工具搭建总结
- OpenWrt内核打补丁方法
- java如何安装tomcat及其底层运用
- CentOS7 上学习使用docker
- 如何通过vSphere客户端打开Linux控制台显示中文
- 了解tomcat
- kali linux 2016.1 滚动更新源
- linux防止攻击
- 跨网站请求伪造
- Linux/CentOS优化配置 汇总
- Linux/CentOS配置:使用yum update更新时不升级内核的方法
- CentOS安装JDK1.7