android 关闭软键盘
2012-08-29 11:15 4444人阅读 评论(0) 收藏 举报
一、
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
//得到InputMethodManager的实例
if (imm.isActive()) { //这行代码貌似没用 软键盘关了的时候都是true
//如果开启
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软键盘控制
本文详细介绍在Android应用中如何控制软键盘的显示与隐藏,提供了多种有效的方法,包括使用InputMethodManager来切换软键盘状态,以及在特定事件下隐藏软键盘的具体实现。
2307

被折叠的 条评论
为什么被折叠?



