如果显示则隐藏 否则弹出弹窗
if (isSoftShowing()) {
final View v = (this).getWindow().peekDecorView();
if (v != null && v.getWindowToken() != null) {
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
} else {
CardPopuUtil.getInstance().showPopu(tvMeBackcardCardtype, tvMeBackcardCardtype, this);
}
判断是否显示方法
private boolean isSoftShowing() {
//获取当屏幕内容的高度
int screenHeight = this.getWindow().getDecorView().getHeight();
//获取View可见区域的bottom
Rect rect = new Rect();
//DecorView即为activity的顶级view
this.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
//考虑到虚拟导航栏的情况(虚拟导航栏情况下:screenHeight = rect.bottom + 虚拟导航栏高度)
//选取screenHeight*2/3进行判断
return screenHeight*2/3 > rect.bottom;
}