美文网首页
Android 监听键盘是否弹出

Android 监听键盘是否弹出

作者: Gao秋 | 来源:发表于2019-08-15 19:43 被阅读0次
private void listenKeyboardVisible() {

finl View contentView = findViewById(android.R.id.content);
    final View activityRoot = getWindow().getDecorView();
    if (activityRoot ==null) {
        return;
    }

contentView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
private final Rectr =new Rect();
private final int visibleThreshold = Math.round(ConvertUtils.dp2px(100));

        @Override
        public void onGlobalLayout() {
            activityRoot.getWindowVisibleDisplayFrame(r);
            int heightDiff =activityRoot.getRootView().getHeight() -r.height();
            //键盘是否弹出
            boolean isOpen = heightDiff >visibleThreshold;

        }

});

}

相关文章

网友评论

      本文标题:Android 监听键盘是否弹出

      本文链接:https://www.haomeiwen.com/subject/puetsctx.html