binding.editText.setOnEditorActionListener { _, actionId, keyEvent ->
val isPushedEnter = actionId == EditorInfo.IME_ACTION_SEARCH ||
actionId == EditorInfo.IME_ACTION_NEXT ||
actionId == EditorInfo.IME_ACTION_DONE ||
(keyEvent != null && keyEvent.action == KeyEvent.ACTION_DOWN &&
keyEvent.keyCode == KeyEvent.KEYCODE_ENTER)
if (isPushedEnter) {
// ソフトキーボードを消す
val imm = requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(rootView.windowToken, InputMethodManager.HIDE_NOT_ALWAYS)
return@setOnEditorActionListener true
} else {
return@setOnEditorActionListener false
}
}
More than 1 year has passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme