首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何打发popupWindow?

如何打发popupWindow?
EN

Stack Overflow用户
提问于 2016-06-11 22:22:31
回答 1查看 71关注 0票数 2

我的活动上有一个PopupWindow。但是,在与我的活动交互后,PopupWindow不会被取消。

当我在不是PopupWindow的屏幕上触摸/滚动/点击/等时,我想关闭弹出窗口。

代码语言:javascript
复制
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),但对我不起作用。

EN

回答 1

Stack Overflow用户

发布于 2016-06-11 22:45:00

代码语言:javascript
复制
 First add
 popupWindow.setOutsideTouchable(true);
and use 
popupWindow.setBackgroundDrawable(new BitmapDrawable(getResources(),
            ""));
or 

popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

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

    }
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37764811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档