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?

EditTextで表示するキーボードを切り替える

Posted at

Androidでフォームに入力する時、数字キーボードやメール用のキーボードを制御する方法をメモします。
EditTextに表示されるキーボードの種類はandroid:inputType で制御します。

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="text" />

テキスト入力(通常)

android:inputType="text"

数字のみ

android:inputType="number"

電話番号用

android:inputType="phone"

+- が入力できる

メールアドレス用

android:inputType="textEmailAddress"

@. が入力できる

パスワード

android:inputType="textPassword"

小数点付きの数字

android:inputType="numberDecimal"

Kotlinから inputType を設定することもできます。画面の状態によってinputを切り替えられます。

数字入力に切り替える

binding.editText.inputType = InputType.TYPE_CLASS_NUMBER

キーボードの見た目はIMEに依存するのとすべての端末で完全に同じ挙動にならないことには注意しましょう。

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?