Prevent other language except English in EditText

筅森魡賤 提交于 2019-12-09 04:32:53

问题


My android app has an EditText field where user can give input. But now i want user can't give input other (i.e Japanese, chain's) than English language.


回答1:


you can limit the user to enter only specific characters in the edit text,

<EditText
    android:id="@+id/nameText"
    android:layout_width="177dp"
    android:layout_height="wrap_content"
    android:inputType="text"
    android:digits="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ" />

By this, the user could only enter English words and space, nothing else..




回答2:


You can add a TextWatcher that checks what the user is trying to enter (and reject what you don't want).

You cannot really check the language, though, but I guess you just want to limit the character set (to ASCII or maybe Latin-1).



来源:https://stackoverflow.com/questions/12171676/prevent-other-language-except-english-in-edittext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!