我的活动上有一个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),但对我不起作用。
发布于 2016-06-11 22:45:00
First add
popupWindow.setOutsideTouchable(true);
and use
popupWindow.setBackgroundDrawable(new BitmapDrawable(getResources(),
""));
or
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
popupWindow.dismiss();
}
});https://stackoverflow.com/questions/37764811
复制相似问题