美文网首页
Android判断键盘是否弹出

Android判断键盘是否弹出

作者: 嘘不要声张 | 来源:发表于2017-06-09 10:27 被阅读0次
View activityView = this.findViewById(android.R.id.content)).getChildAt(0);
int height = activity.getHeight();
int screenHeight = this.getWindowManager().getDefaultDisplay().getHeight() - getStatusHeight();
if (height > 0 && height < screenHeight) {
        // 键盘打开状态

}

// 获取状态栏高度
public int getStatusHeight() {
        Class<?> c = null;
        Object obj = null;
        Field field = null;
        int x = 0, barHeight = 0;
        try {
            c = Class.forName("com.android.internal.R$dimen");
            obj = c.newInstance();
            field = c.getField("status_bar_height");
            x = Integer.parseInt(field.get(obj).toString());
            barHeight = CacheManager.get().getContext().getResources().getDimensionPixelSize(x);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        return barHeight;
    }

相关文章

网友评论

      本文标题:Android判断键盘是否弹出

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