diff --git a/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java b/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java index 925cf4e1..9bb8dff2 100644 --- a/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java +++ b/library/src/main/java/com/lxj/xpopup/core/BasePopupView.java @@ -153,6 +153,7 @@ public void run() { KeyboardUtils.registerSoftInputChangedListener(getHostWindow(), BasePopupView.this, new KeyboardUtils.OnSoftInputChangedListener() { @Override public void onSoftInputChanged(int height) { + onKeyboardHeightChanged(height); if(popupInfo!=null && popupInfo.xPopupCallback!=null) { popupInfo.xPopupCallback.onKeyBoardStateChanged(BasePopupView.this,height); } @@ -574,6 +575,11 @@ protected void beforeDismiss(){} protected void onShow() { } + /** + * 当键盘高度改变时调用 + */ + protected void onKeyboardHeightChanged(int height) {} + @OnLifecycleEvent(value = Lifecycle.Event.ON_DESTROY) public void onDestroy(){ destroy(); @@ -656,6 +662,8 @@ public boolean onTouchEvent(MotionEvent event) { y = 0; break; } + } else { + passClickThrough(event); } return true; } diff --git a/library/src/main/java/com/lxj/xpopup/util/XPopupUtils.java b/library/src/main/java/com/lxj/xpopup/util/XPopupUtils.java index 27ee86d8..0613a3dd 100644 --- a/library/src/main/java/com/lxj/xpopup/util/XPopupUtils.java +++ b/library/src/main/java/com/lxj/xpopup/util/XPopupUtils.java @@ -215,7 +215,8 @@ public static int getDecorViewInvisibleHeight(final Window window) { //监听到的keyboardHeight有一定几率是错误的,比如在同时显示导航栏和弹出输入法的时候,有一定几率会算上导航栏的高度, //这个不是必现的,暂时无解 - private static int correctKeyboardHeight = 0; + //为了方便用户修改键盘高度和获取当前键盘高度 + static int correctKeyboardHeight = 0; public static void moveUpToKeyboard(final int keyboardHeight, final BasePopupView pv) { if (correctKeyboardHeight == 0) correctKeyboardHeight = keyboardHeight; @@ -229,6 +230,17 @@ public void run() { }); } + //如果变化键盘高度,需要调整弹窗,请使用SimpleCallback,重写onKeyBoardStateChanged,在onKeyBoardStateChanged中调用XPopupUtils.moveUpToKeyboardNow + //或者重写popupView中的onKeyboardHeightChanged + //此处修改correctKeyboardHeight是为了修复打开其他弹窗时键盘高度不对导致遮挡输入框问题 + public static void moveUpToKeyboardNow(final int keyboardHeight, final BasePopupView pv) { + correctKeyboardHeight = keyboardHeight; + pv.getPopupContentView().animate().translationY(-keyboardHeight) + .setDuration(200) + .setInterpolator(new OvershootInterpolator(0)) + .start(); + } + private static void moveUpToKeyboardInternal(int keyboardHeight, BasePopupView pv) { if (pv.popupInfo == null || !pv.popupInfo.isMoveUpToKeyboard) return; //暂时忽略PartShadow弹窗和AttachPopupView