PopupWindow 裡邊有輸入框,輸入法彈出將其遮擋解決方法
阿新 • • 發佈:2019-02-19
具體如下 :
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);