PopupWindow响应返回键的问题
假设情景是这样的:在一个Activity中弹出一个PopupWindow,要求在按返回键时关闭该PopupWindow。
如果该PopupWindow是无焦点的(默认情况),那么可以在Activity中响应返回键(onBackPressed),然后关闭它。
如果该PopupWindow是有焦点的,那么在它弹出来之后,所有的按键和触摸事件都会被它截获,包括返回键。
让PopupWindow获得焦点有两种方法,第一种是在创建的时候指定,第二种是在创建之后,调用它的setFocusable方法指定。
但是仅仅使PopupWindow获得焦点还不行,此时它不响应返回键,也就是说,按返回键的时候PopupWindow并不会关闭。
如果需要PopupWindow响应返回键,那么必须给PopupWindow设置一个背景才行,下面是通常的做法:
setFocusable(true);
ColorDrawable dw = new ColorDrawable(0x00000000);
setBackgroundDrawable(dw);
PopupWindow响应返回键的问题的更多相关文章
- android fragment轻松监听返回键/Fragment中的popupwindow响应返回键隐藏
现在的开发我们基本上都是一个主activity中放多个fragment,点击返回按钮的时候,直接退出主activity,但是我们在fragment中经常会弹出例如popupWindow这样的布局,用户 ...
- Fragment响应返回键
Activty可以直接响应返回键,而Fragment却不行,可用如下方式: 创建一个抽象类BackHandledFragment,该类中有一个抽象方法onBackPress(),所有BackHandl ...
- cocos2d-x在android中响应返回键编译报错的bug分析
先看一段代码如何在Android中加入返回按键的响应 <span style="font-size:18px;">自己派生CCKeypadDelegate的子类,然后注 ...
- [android] 实现返回键操作思路
记录用户点击的操作历史,使用栈数据结构,频繁的操作栈顶(添加,获取,删除),使用LinkedList 捕获用户的返回键操作,响应返回键,返回上一个界面 MainActivity.java /** * ...
- popupWindow设置后完美解决返回键响应无效的方案以及popupWindow背景透明方案
// 点击其他地方消失 viewPuwAddNew.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouc ...
- PopupWindow 点击外部和返回键无法消失背后的真相(setBackgroundDrawable(Drawable background))
刚接手PopupWindow的时候,我们都可能觉得很简单,因为它确实很简单,不过运气不好的可能就会踩到一个坑: 点击PopupWindow最外层布局以及点击返回键PopupWindow不会消失 新手在 ...
- Unity响应Android的返回键,退出当前Activity
一:使用 Application.Quit() public void Update() { if(Input.GetKeyDown(KeyCode.Escape)) Application.Quit ...
- 点击返回键退出popupwindow的方法
点击返回键退出popupwindow mPopupWindow.setFocusable(true); 这句非常重要,对背景不会有影响 mPopupWindow.setBackgroundDrawab ...
- Android popupwindow和dialog监听返回键
使用情况: 在activity中,出现了popupwindow和dialog,这个时候,如果点击返回键,它们消失了,但是一些操作还在继续.如:1.进行耗时操作,出现dialog提醒用户等待,这时,按下 ...
随机推荐
- 解读Unity中的CG编写Shader系列十 (光滑的镜面反射(冯氏着色))
前文完成了最基本的镜面反射着色器,单平行光源下的逐顶点着色(per-vertex lighting),又称为古罗着色(Gouraud shading).这篇文章作为后续讨论更光滑的镜面反射方式,逐像素 ...
- ffmpeg-20160629-git-bin.7z
ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 f ...
- Java for LeetCode 235 Lowest Common Ancestor of a Binary Search Tree
递归实现如下: public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if(p.val>ro ...
- Java for LeetCode 221 Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ret ...
- Java for LeetCode 209 Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a subarra ...
- Android Volley入门到精通:定制自己的Request
经过前面两篇文章的学习,我们已经掌握了Volley各种Request的使用方法,包括StringRequest.JsonRequest.ImageRequest等.其中StringRequest用于请 ...
- linux日常易忘指令
1.编辑全局指令 进入~/.bash_profile 增加"exprot +(启动文件的地址)" source ~/.bash_profilr(刷新) 2.修改mysql密码 my ...
- Mysql子查询
1单值(Scalar operand) 只有当外层(Parent)不为空时,才返回相应值:否则返回NULL. note:For the subquery just shown, if t1 were ...
- jq div鼠标放上、离开马上展开、收缩方法
<body> <div id="aa" style="width:500px; height:30px; border:1px solid #000&q ...
- CLR via C#(03)- 对象创建和类型转换
一. 创建对象 CLR要求用new操作符创建对象,这个操作符在编译时产生的IL指令为newobj.例如: Student XiaoJing=new Student(“XiaoJing”,”1986”) ...