PopupWindow 用法 PopupWindow不消失 解决方法

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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值