在我的布局中有一个用于搜索的 EditText,并且在 EditText 下方有一个列表。现在我在 PopupWindow 中膨胀这个布局。现在我的问题是
1)如果我将 PopupWindow focusable 设置为 true ,那么除了 PopupWindow 布局之外的所有地方都变得不可点击。所以我不能通过点击外部或点击设备的后退按钮来关闭窗口
2)如果我设置 PopupWindow focusable false ,那么 Popupwindow 打开和关闭是完美的,但是在点击 EditText 时软键盘不可见
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// Inflate the view from a predefined XML layout View layout = inflater.inflate(R.layout.popup_layout, null);
mPopUpWindow= new PopupWindow(layout,0, mScreenHeight - 100, false);
mPopUpWindow.setBackgroundDrawable(null);
mPopUpWindow.setOutsideTouchable(true);
mPopUpWindow.setTouchInterceptor(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
mPopUpWindow.dismiss();
}
return false;
}
});
final InputMethodManager inputMgr = (InputMethodManager) MainApplication.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
inputMgr.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT);
mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
inputMgr.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
return true;
}
return false;
}
});