1

I have 3 languages on my keyboard in android device and I want to show only English language letters and numbers when starting to edit text inside EditText like username field , I tried to use this line in xml file for Edittext but without any result.

android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"
Owen Pauling
  • 11,349
  • 20
  • 53
  • 64
Samah Ahmed
  • 419
  • 8
  • 24
  • 1
    I think you should change the title of your question. I got the impression that you are asking how to prevent the user from using a non-english **keyboard**. Which is probably not possible. – GhostCat Dec 20 '16 at 12:38
  • possible duplicate of http://stackoverflow.com/questions/4324248/how-to-force-english-keyboard-in-android-edittext?rq=1 – Ranjan Dec 20 '16 at 12:39
  • Somewhat related to this one: https://stackoverflow.com/questions/16578009/my-edittext-will-accept-numbers-only-in-english-is-there-a-way-to-change-that-a – Sufian Oct 31 '19 at 15:16

1 Answers1

1

the best way is to use inputfilter and set it to your editText you can see a workaround to do that here :

How do I use InputFilter to limit characters in an EditText in Android?

also i found a code snippet to this like below:

InputFilter filter = new InputFilter() {
public CharSequence filter(CharSequence source, int start, int end, 
    Spanned dest, int dstart, int dend)
{
    for (int i = start; i < end; i++) {
        if (!isEnglishOrHebrew(source.charAt(i))) { 
            return "";
        }
    }
    return null; 
}

private boolean isEnglishOrHebrew(char c) {
    . . .
}
}; 

edit.setFilters(new InputFilter[]{filter});
Community
  • 1
  • 1
Amir Ziarati
  • 14,248
  • 11
  • 47
  • 52