android 关闭软键盘
16lz
2022-01-24
一、 InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
//得到InputMethodManager的实例
if (imm.isActive()) {
//如果开启
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);
//关闭软键盘,开启方法相同,这个方法是切换开启与关闭状态的
}
------------------------------------------
//隐藏软键盘-可行
int flags = WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
getWindow().addFlags(flags);
--------------------------------------------
在onclick事件下.以下方法可行.(如果是EditText失去焦点/得到焦点,没有效果)
InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(getCurrentFocus().getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 二、
//得到InputMethodManager的实例
if (imm.isActive()) {
//如果开启
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);
//关闭软键盘,开启方法相同,这个方法是切换开启与关闭状态的
}
------------------------------------------
//隐藏软键盘-可行
int flags = WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
getWindow().addFlags(flags);
--------------------------------------------
在onclick事件下.以下方法可行.(如果是EditText失去焦点/得到焦点,没有效果)
InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(getCurrentFocus().getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 二、
// 关闭键盘
public void KeyBoardCancle() {
View view = getWindow().peekDecorView();
if (view != null) {
InputMethodManager inputmanger = (InputMethodManager) getSystemService(ActivityBase.INPUT_METHOD_SERVICE);
inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
更多相关文章
- Android(安卓)实现Activity后台运行
- android点击空白区域隐藏软键盘的实现
- Android(安卓)Dialog中EditText自动弹出软键盘
- android 关闭数据连接方法
- Android(安卓)开启闪光灯做手电筒 源码
- WiFi的使用Demo
- android中隐藏以及显示软键盘代码
- android 键盘不弹出
- Android(安卓)打开和关闭软键盘