作者:mmlouie | 来源:互联网 | 2023-02-07 09:24
我遇到了一个editText的情况.当我在编辑文本中按添加时,我在列表中添加成员.何时添加(或不添加)我正在打开自定义对话框.
在我的活动中,当点击编辑文本中的添加按钮时,我有这个代码:
customDialogTeamMember = new CustomDialogTeamMember(............);
customDialogTeamMember.makeDialog();
editText.getText().clear();
editText.clearFocus();
hideSoftKeyboard();
我的hideSoftKeyboard()定义如下:
public void hideSoftKeyboard() {
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
此方法适用于应用程序的其他部分.但这里没有用!
自定义对话框打开.当我关闭它时,键盘保持在屏幕上.可能是什么问题呢?!
1> 小智..:
显示和隐藏键盘
InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
//Hide:
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
//Show
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
private void hideKeyboard() {
// Check if no view has focus:
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
private void showKeyboard() {
// Check if no view has focus:
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
}