简单的问题 - 如何在按下回车键/按钮后关闭虚拟键盘?
我试过这个 Handle “Enter” key on Jelly Bean和 How to hide keyboard on enter key ,但这些都不适合我。
最佳答案
你有两个选择。
使用 xml:
<EditText
android:id="@+id/editText1"
android:inputType="text"
android:imeOptions="actionDone"/>
和代码。
edittext.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event != null&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
in.hideSoftInputFromWindow(edittext.getApplicationWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
}
return false;
}
});
关于android - 按下回车键后隐藏键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23251605/