设为首页 加入收藏

TOP

隐藏键盘
2019-08-30 07:27:00 】 浏览:25
Tags:隐藏 键盘
/**
* 判断键盘是否显示
*
* @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);
}
}
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇安卓开发笔记(十八):实现butto.. 下一篇Android之Retrofit详解(转载)

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目