View rootView = getWindow().getDecorView().getRootView();
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
private boolean is = false;
@Override
public void onGlobalLayout() {
Rect r = new Rect();
rootView.getWindowVisibleDisplayFrame(r);
int screenHeight = rootView.getRootView().getHeight();
int keypadHeight = screenHeight - r.bottom;
if (keypadHeight > screenHeight * 0.15) {
if (is){
is = false;
// 软键盘弹出
LogUtils.d("MessageActivity","软键盘弹出");
}
} else {
if (!is){
is = true;
// 软键盘隐藏
LogUtils.d("MessageActivity","软键盘隐藏");
}
}
}
});
Android 判断键盘输入法是否弹出
最新推荐文章于 2024-09-02 18:19:21 发布