gpt4 book ai didi

java - 如何关闭popupWindow?

转载 作者:行者123 更新时间:2023-12-01 16:11:10 24 4
gpt4 key购买 nike

我的 Activity 上有一个PopupWindow。但是,与我的 Activity 进行交互后,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),但对我不起作用。

最佳答案

 First add
popupWindow.setOutsideTouchable(true);
and use
popupWindow.setBackgroundDrawable(new BitmapDrawable(getResources(),
""));
or

popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

@Override
public void onDismiss() {
popupWindow.dismiss();

}
});

关于java - 如何关闭popupWindow?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37764811/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com