Android 中在EditText中设置输入限制,使输入字符只可以为数字。

时间:2021-05-21 04:31:38

在某些输入框中我们只需要输入数字而不希望有其他字符被输入,这时可以这样设置:

<EditText

android:id="@+id/text"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:digits="0123456789"

/>

0123456789表示允许输入的字符,要是不允许输入0和1,可以这样

android:digits="23456789"