Search code examples
androidandroid-softkeyboard

EditText with only ascii letters. How?


Primary users of my app have 2 languages installed. English and other. Default system language is not English. Users just use language switch button on software keyboard.

One specific EditText field in my app needs to accept only A-Z(capitalization issue is not a problem) and spaces and no other characters (no digits, no non-latin chars,etc).

I understood about solutions with InputFilters like How to create EditText accepts Alphabets only in android? or with TextWatcher-derived but thy only allow app to simple ignore incorrect text and I need to be able to make user not even able to see non-latin1 letters in first place on their on-screen keyboard (I'm aware that it is possible to use hardware keyboard, this is not issue at this time).

android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
Doesn't help too (language change button is still visible in keyboard).

I need something like iPhone: Change Keyboard language programmatically but for Android.

Do I have any other option except adding fake keyboard to my app?

iOS have .keyboardType = .asciiCapable and it works in such situations


Solution

  • I found at least semi-working solution based on https://stackoverflow.com/a/49710730/1063214

    imeOptions="flagForceAscii"  
    

    on EditText.

    Now at least non-english keyboard is not shown (and digits,etc are filtered anyway).