隐藏键盘

/** * 判断键盘是否显示 * * @return true 显示 */public static boolean isSoftShowing(Activity activity) { //获取当前屏幕内容的高度 int screenHeight = activity.getWindow().getDe...
/**
* 判断键盘是否显示
*
* @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);
}
}
  • 发表于 2019-04-03 08:00
  • 阅读 ( 163 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除