关于popupWindow点击外层不能消失的问题

直接上popupwindow的代码

    if (hotWordsList != null && hotWordsList.size() >= 1) {
        searchAText.setText(hotWordsList.get(0));
        mPopup_search_hot_word_layout = LayoutInflater.from(this).inflate(R.layout.popup_search_hotword_layout, null);
        mHotWordPopWindow = new PopupWindow(mPopup_search_hot_word_layout,
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);
    }
    ListView popListView = (ListView) mPopup_search_hot_word_layout.findViewById(R.id.popup_search_hot_word_list);
    HotWordPopupAdapter hotWordPopupAdapter = new HotWordPopupAdapter(SttmFristActivity.this, hotWordsList);
    popListView.setAdapter(hotWordPopupAdapter);
    mHotWordPopWindow.setTouchable(true); // 设置popupwindow可点击
    mHotWordPopWindow.setOutsideTouchable(true); // 设置popupwindow外部可点击

点击外部无法消失,废话
其实这是个小坑,popupwindow要设置背景才能点击其他地方关闭,背景随你设置成什么颜色

 mHotWordPopWindow.setBackgroundDrawable(new BitmapDrawable());

你可能感兴趣的:(关于popupWindow点击外层不能消失的问题)