这个问题不是要求代码中的任何帮助,而是如何在Android应用程序中进行键盘使用。
我正在构建一个应用程序。我的想法是创建一个名为HideKeyboard.java
的单独类,它将包含关闭android软键盘的代码,并在我使用EditText Field.
这种做法是好的还是我应该尝试任何其他方法。请建议
先谢谢。
答案 0 :(得分:2)
使用此方法隐藏键盘
private void hideKeyboard() {
InputMethodManager inputManager = (InputMethodManager) getApplicationContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
System.out.println("in hidemehod");
if (this.getCurrentFocus() != null) {
System.out.println("hide");
((InputMethodManager) EarnedRewardActivity.this
.getSystemService(Context.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(this.getCurrentFocus()
.getWindowToken(), 0);
/*
* inputManager.hideSoftInputFromWindow(
* this.getCurrentFocus().getWindowToken(),
* InputMethodManager.HIDE_NOT_ALWAYS);
*/
}
}