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);

其中  

popupWindow = new PopupWindow(getLayoutInflater().inflate(R.layout.newpopupwindow, null),300,300);
popupWindow = new PopupWindow(getLayoutInflater().inflate(R.layout.newpopupwindow, null),300,300,true);
popupWindow = new PopupWindow(getLayoutInflater().inflate(R.layout.newpopupwindow, null),300,300,false);
这三者没区别
API解释为 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.

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

你可能感兴趣的:(Android,学习)