0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Android】文字入力時のキーボード操作のメモ【Kotlin】

Posted at

はじめに

Editテキスト入力時のキーボードの操作でエンターキーやバックキーなどのアクションキーが押された時の処理を完全に覚えきれず、何度も調べながら実装するのが面倒になったので 特に使いそうなものを自分の記事に残しておこうと思いました。

実装

自分用なのでかなり簡単にではありますが、以下が実装内容です。

 editText.setOnKeyListener(View.OnKeyListener { _, action, event ->
        if (event.action == KeyEvent.ACTION_DOWN) {
            if (action == EditorInfo.IME_ACTION_DONE) {
                // Enterが押された
            }

            if (action == KeyEvent.KEYCODE_DEL) {
                // バックスペースが押された
            }
        }
        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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?