【发布时间】:2016-06-11 14:22:31
【问题描述】:
我的活动中有PopupWindow。但是,PopupWindow 在与我的活动交互后不会被关闭。
当我在不是PopupWindow的屏幕上触摸/滚动/单击/等时,我想关闭弹出窗口。
public class ListViewForDeleteContact extends AppCompatActivity {
ListView myListView;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.listviewfordeletecontactlayout_main);
myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
LayoutInflater layoutInflater=(LayoutInflater)ListViewForDeleteContact.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View dfg= layoutInflater.inflate(R.layout.popupwindowfordeletelayout_main,(ViewGroup)findViewById(R.id.popupId));
PopupWindow popupWindow=new PopupWindow(dfg,420,300,true);
popupWindow.showAtLocation(dfg, Gravity.CENTER, 0, 0);
popupWindow.setOutsideTouchable(true);
}
});
}
}
我尝试了一些方法,例如 setOutsideTouchable(true); 和 setBackgroundDrawable(true),但对我不起作用。
【问题讨论】:
-
你试过这个答案吗? stackoverflow.com/a/17974653/4860513
-
@Guilherme P 现在我试过了,但没用