Android之打开和关闭软键盘
16lz
2022-04-24
//调用隐藏系统默认
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
//设置控件属性:
android:fitsSystemWindows="true"
显示键盘
public void showInput(EditText editText) { editText.requestFocus(); InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);}
隐藏键盘
public void hideInput() { InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); View v = getWindow().peekDecorView(); if (null != v) { //强制隐藏键盘 imm.hideSoftInputFromWindow(v.getWindowToken(), 0); }}
获取打开的状态
public boolean getIsOpen() { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); return imm.isActive();}
更多相关文章
- android 自带的下拉刷新控件,含Demo(SwipeRefreshLayout控件)
- Android(安卓)动态设置控件高度
- Android的GridView控件点击图片变暗效果
- android 自带的下拉刷新控件,含Demo(SwipeRefreshLayout控件)
- android 控件跟随手指移动,类似捕鱼达人效果
- android performClick
- android 应用程序 集合
- android 关闭软键盘
- Android(安卓)反射获得控件对象