问题
I want from my EditText to accept only certain characters. I don`t want to filter them in listener, I want to set it in XML permanently.
I want to use only these characters:
0123456789abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWYZ
So I made string and add that to android:digits.
I want to convert each lowercase letter to uppercase (I dont want to disable typing without shift just convert them)
I used android:textAllCaps="true" but this doesnt work.
回答1:
Try this, This will help you for sure.
editText.setFilters(new InputFilter[] {new InputFilter.AllCaps()});
回答2:
You can do it in XML file
android:digits="0123456789abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWYZ"
Possible duplicate: How to restrict the EditText to accept only alphanumeric characters
来源:https://stackoverflow.com/questions/56495984/how-to-force-edittext-to-accept-only-specific-alphanumerical-characters