具体如下 :
private void writeDelivery() {
View layout = getLayoutInflater().inflate(R.layout.dialog_write_delivery,null);
EditText inputCmpny = (EditText) layout.findViewById(R.id.inputCmpny);
EditText inputExprNum = (EditText) layout.findViewById(R.id.inputExprNum);
int H;
H = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
layout.measure(0, H);
H = layout.getMeasuredHeight();
pop = new PopupWindow(layout, DeviceUtil.getScreenPixels(this).getWidth(), H);
ColorDrawable cd = new ColorDrawable(-0000);
pop.setBackgroundDrawable(cd);
// 设置出现和消失样式
pop.setAnimationStyle(R.style.vertical_slide);
pop.update();
pop.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
pop.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
pop.setTouchable(true); // 设置popupwindow可点击
pop.setOutsideTouchable(true); // 设置popupwindow外部可点击
pop.setFocusable(true); // 获取焦点
pop.showAtLocation(layout, Gravity.BOTTOM, 0, 0);
// 设置动画
setAlphaValueAnimation(1.0f, 0.5f);
pop.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
// 设置动画
setAlphaValueAnimation(0.5f, 1.0f);
}
});
pop.setTouchInterceptor(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
/**** 如果点击了popupwindow的外部,popupwindow也会消失 ****/
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
pop.dismiss();
return true;
}
return false;
}
});
}
主要的解决地方 :
//这句话,让pop覆盖在输入法上面
pop.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
//这句话,让pop自适应输入状态
pop.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);