0
0

More than 1 year has passed since last update.

EditTextでエンターキーが押されたらSWキーボードを閉じる

Posted at
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
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0