隐藏键盘
程序员文章站
2022-06-27 17:04:48
/** * 判断键盘是否显示 * * @return true 显示 */public static boolean isSoftShowing(Activity activity) { //获取当前屏幕内容的高度 int screenHeight = activity.getWindow().ge ......
/**
* 判断键盘是否显示
*
* @return true 显示
*/
public static boolean issoftshowing(activity activity) {
//获取当前屏幕内容的高度
int screenheight = activity.getwindow().getdecorview().getheight();
//获取view可见区域的bottom
rect rect = new rect();
activity.getwindow().getdecorview().getwindowvisibledisplayframe(rect);
return screenheight - rect.bottom != 0;
}
/**
* 隐藏键盘
*/
public static void hide(activity activity) {
if (issoftshowing(activity)){
inputmethodmanager imm = (inputmethodmanager) activity.getsystemservice(context.input_method_service);
imm.togglesoftinput(0, inputmethodmanager.hide_not_always);
}
}