PopupWindow 用法 PopupWindow不消失 解决方法

来源:互联网 发布:医学影像工作站软件 编辑:程序博客网 时间:2024/06/09 19:04

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之前就已经执行了

0 0
原创粉丝点击