5

We are working on a multilingual Android app, targeting both English & Arabic. An issue being faced is in the Login & Registration screens, where we want the username and password fields to be entered only in English text & thus display the English keyboard, irrespective of the device locale language

Have tried setting the inputtype="email" in edittext but, this didn't work as desired.

Can someone please point out if there are any possibilities.

Thanks & regards, Jigar J

Jigar Joshi
  • 261
  • 2
  • 7

2 Answers2

15

Finally got the solution.

Usecase : Enforcing user to enter input in ‘English’ regardless of current Locale set in App(Local) or Phone (System Locale)


Solution : We have the property of EditText control called ‘imeOptions’ which allows to restrict user to enter text of specific ‘input type’.

In order to restrict user to enter ‘english’ text we only need to use ‘flagForceAscii’ property.


Usage: Via xml :

android:imeOptions="flagForceAscii"

Via java:

editText.setImeOptions(EditorInfo.IME_FLAG_FORCE_ASCII);

Version Compatibility :

This attribute was adden in API16, aka Jellybean

Ali Bdeir
  • 4,151
  • 10
  • 57
  • 117
Jigar Joshi
  • 261
  • 2
  • 7
  • what about if i have to add next ime option along with this flag? .. i have to use "actionNext" and "flagForceAscii" both – Usman Ghauri Feb 08 '17 at 08:38
  • @UsmanGhauri You can use it like this: `android:imeOptions:"actionNext|flagForceAscii"` – Assan Jan 19 '18 at 11:03
  • 1
    @Assan It is not working for me. Can you please help ? I am on arabic default language but I want to see only english language keyboard, flagForceAscii is still showing me arabic keyboard ? – Gaurav Arora Feb 20 '19 at 05:21
  • @GauravArora I don't know why it isn't working for you, but maybe the virtual keyboard that you're using ignores this flag for some reason. I'm using the Google keyboard, and it doesn't switch to anything but English, even if I don't add it as one of the languages. – Assan Feb 21 '19 at 06:34
-1

You can probably look at these two posts.

  1. how to force english keyboard in android EditText

  2. How do I change the default keyboard input language in EditText in Android

Hope this helps!

Community
  • 1
  • 1
Saumik Bhattacharya
  • 891
  • 1
  • 12
  • 28