您的位置:首页 > 运维架构

PopupWindow 用法 PopupWindow不消失 解决方法

2015-08-31 09:32 302 查看
PopupWindow创建

popupWindow = new PopupWindow(getLayoutInflater().inflate(R.layout.newpopupwindow, null),300,300);
		popupWindow.setFocusable(true);
		popupWindow.setBackgroundDrawable(Test.this.getResources().getDrawable(R.drawable.ic_launcher));
		popupWindow.setOutsideTouchable(true);
		popupWindow.showAsDropDown(v, 0,0);


其中
</pre><pre name="code" class="html">popupWindow = new PopupWindow(getLayoutInflater().inflate(R.layout.newpopupwindow, null),300,300);
<pre name="code" class="html">popupWindow = new PopupWindow(getLayoutInflater().inflate(R.layout.newpopupwindow, null),300,300,true);
<pre name="code" class="html">popupWindow = new PopupWindow(getLayoutInflater().inflate(R.layout.newpopupwindow, null),300,300,false);
这三者没区别
API解释为 <span style="font-family: Arial, Helvetica, sans-serif;">A popup window that can be used to display an arbitrary view. The popup window is a floating container that appears on top of the current activity.</span>


其中new PopupWindow 中的第一个参数为自定义的view 后面两个分别为PopupWindow宽和高

.setFocusable() 设置PopupWindow 是不是能接受焦点

.setoutsideTouchable PopupWindow外面能不能点击 点击之后会使PopupWindow 消失 dismiss()

showASDropDown 显示的方式

假如设置了 setBackgroundDrawable 就算没有设置 .setoutsideTouchable 也可以点击popupwindow之外的地方使popupwindow消失

只设置了 setfocusable 而没设置 setbackgroundDrawable 点击Popupwindow 之外的地方 popupwindow不消失

PopupWindow 无法消失的情况 解决方法:

1.只设置了 setfocusable 而没设置 setbackgroundDrawable 点击Popupwindow 之外的地方 popupwindow不消失

2.showAsDropDown 在PopWindow设置完setbackgrounddrawable之前就已经执行了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: