我的活动有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)
,但它对我不起作用。
答案 0 :(得分:0)
First add
popupWindow.setOutsideTouchable(true);
and use
popupWindow.setBackgroundDrawable(new BitmapDrawable(getResources(),
""));
or
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
popupWindow.dismiss();
}
});