android 键盘关闭/显示
16lz
2021-12-04
android 键盘关闭/显示
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);
更多相关文章
- android 键盘显示与隐藏
- 安卓基础知识
- StevGuo系列文章翻译之Talking about Android(安卓)process
- 开启 Android(安卓)反射调用
- Android(安卓)设置EditText不会自动弹出键盘
- JS与Android交互之html页面跳转到Android(安卓)Activity
- android键盘弹出之后界面整体上移,顶出去了
- android键盘弹出之后界面整体上移,顶出去了
- android EditText中的inputType .