点击返回键退出popupwindow
mPopupWindow.setFocusable(true);
这句非常重要,对背景不会有影响
mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
然后再设置它的键监听器
mView.setOnKeyListener(onKeyListener);
private OnKeyListener onKeyListener=new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_BACK){
dismiss();
return true;
}
return false;
}
};