软件盘的隐藏

if (imm !=null&&isSoftShowing()) {

imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);

imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

}

谷歌官网没有给出软键盘是否弹出的api,只能自己通过计算软键盘的高度来判断软键盘是不是显示了
public boolean isSoftShowing() {

//获取当前屏幕内容的高度

    int screenHeight = getWindow().getDecorView().getHeight();

//获取View可见区域的bottom

    Rect rect =new Rect();

//DecorView即为activity的顶级view

    getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);

//考虑到虚拟导航栏的情况(虚拟导航栏情况下:screenHeight = rect.bottom + 虚拟导航栏高度)

//选取screenHeight*2/3进行判断

    return screenHeight *2 /3 > rect.bottom;

}

你可能感兴趣的:(软件盘的隐藏)