1.一般修改
private boolean isInputMethodShowing() {
//获取当前屏幕内容的高度
int screenHeight = getWindow().getDecorView().getHeight();
//获取View可见区域的bottom
Rect rect = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
return screenHeight - rect.bottom - getSoftButtonsBarHeight() != 0;
}
/**
* 底部虚拟按键栏的高度
* @return
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private int getSoftButtonsBarHeight() {
DisplayMetrics metrics = new DisplayMetrics();
//这个方法获取可能不是真实屏幕的高度
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int usableHeight = metrics.heightPixels;
//获取当前屏幕的真实高度
getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
int realHeight = metrics.heightPixels;
if (realHeight > usableHeight) {
return realHeight - usableHeight;
} else {
return 0;
}
}
2. framework修改
public boolean isActive() {
checkFocus();
synchronized (mH) {
//return mServedView != null && mCurrentTextBoxAttribute != null;
return mServedView != null && mCurrentTextBoxAttribute != null && (getInputMethodWindowVisibleHeight() > 0);
}
}