問題描述
如何限制 Android EditText 字段中的特殊字符?
How to restrict special characters from an Android EditText field?
推薦答案
你試過添加 android:digits="abcde.....0123456789"
屬性嗎?雖然 android:digits
指定它是一個數字字段,但我可以將其設置為也接受字母和特殊字符(在 SDK-7 上測試).
Have you tried adding the android:digits="abcde.....0123456789"
attribute?
Although the android:digits
specify that it is a numeric field, it does work for me to set it to accept letters as well, and special characters as well (tested on SDK-7).
如果這不起作用,那么您將不得不實現 KeyListener
請參閱:http://developer.android.com/reference/android/widget/TextView.html#setKeyListener(android.text.method.KeyListener)
If this doesn't work then you'll have to implement KeyListener
see: http://developer.android.com/reference/android/widget/TextView.html#setKeyListener(android.text.method.KeyListener)
這篇關于如何限制 Android EditText 字段中的特殊字符?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!