示例代码:
PopupWindow popupWindow = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true); popupWindow.setFocusable(true);
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { // 处理dismiss事件 } });
popupWindow.setContentView(view);
popupWindow.showAtLocation(parentView, Gravity.BOTTOM, 0, 0); popupWindow.setAnimationStyle(R.style.Animation);
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && popupWindow.isShowing()) { popupWindow.dismiss(); return true; } return super.onKeyDown(keyCode, event); }