如何限制Android的编辑文本字段只针对某些选定的字符字段、字符、文本、编辑

2023-09-05 07:34:18 作者:且放白鹿青崖间

有没有什么办法来限制允许输入时只有某些选定的字符集的用户(例如:A或B或C或D)的安卓layout.xml

Is there any way to limit users allowed to type only some selected character set (Eg: A or B or C or D) in Android layout.xml

推荐答案

使用的digits属性,只能传递给位的字符将在允许的EditText。

Use the digits attribute, only the characters passed to digits will be allowed in the EditText.

android:digits="abc123"

是的,数字是一个误导性的名称,它接受字母和符号了。

And yes, "digits" is a misleading name, it accepts letters and symbols too.