//调用隐藏系统默认
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();
}
网友评论