//设置弹出窗体需要软键盘,
popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
//再设置模式,和Activity的一样,覆盖,调整大小。
popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
//activity设置属性:
android:windowSoftInputMode="adjustPan"
解决Android7.0后pop显示位置不正确的问题
/**
* 相对于父控件的位置(通过设置Gravity.CENTER,下方Gravity.BOTTOM等 ),可以设置具体位置坐标
* @return
*/
public CustomPopWindow showAtLocation(View view){
/*
* 此方法针对7.0部分机型PopupWindow弹出位置不正确的解决方法
*/
if (mPopupWindow != null && mPopupWindow.isShowing()) {
mPopupWindow.dismiss();
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
int[] location = new int[2];
view.getLocationOnScreen(location);
int tempHeight = mPopupWindow.getHeight();
if (tempHeight == WindowManager.LayoutParams.MATCH_PARENT || DisplayUtils.getScreenHeight(mContext) <=
tempHeight) {
mPopupWindow.setHeight(DisplayUtils.getScreenHeight(mContext) - location[1] - view.getHeight());
}
mPopupWindow.showAtLocation(view, Gravity.NO_GRAVITY, location[0], location[1] + view.getHeight());
mPopupWindow.update();
} else {
if (mPopupWindow != null) {
mPopupWindow.showAsDropDown(view, 0, 0);
mPopupWindow.update();
}
}
}
return this;
}
网友评论