1

I am dynamically creating an EditText and I want to disable auto-capitalization on any sentences (new lines).

I have tried a variation of flags for EditText.setInputType(int) but none of them have accomplished disabling the shift key being enabled on new lines.


Here is my code:

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
EditText editText = new EditText(context);
int type = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE
            | InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE;
if (preferences.getBoolean("disable_suggestions", true)) {
    type |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
                | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
}
if (preferences.getBoolean("disable_auto_capitalization", true)) {
    //
    // TODO: StackOverflow to the rescue! What flag do I need? 
    //
}
editText.setInputType(type);

I have searched StackOverflow extensively for an answer and the only question I found was this.

Community
  • 1
  • 1
  • Please understand that `setInputType()` is a request, not a command, and therefore not all input method editors (a.k.a., soft keyboards) will honor your request. AFAIK, what you have there should be OK. – CommonsWare Jun 13 '15 at 23:23
  • Thank you @CommonsWare for giving your input. Are you suggesting that it is impossible to disable auto-capitalization? –  Jun 14 '15 at 13:25
  • It is impossible to guarantee disabled auto-capitalization across all devices. Again, what you have should be OK from what I can tell. If you are trying it on some device, and the device still auto-capitalizes, try your app on the official Android SDK emulator. If it behaves properly there, you know that your device, or the input method editor you installed on that device, is the source of your problem, and there is nothing that you can do about it. If, OTOH, the Android SDK emulator *also* auto-capitalizes, then perhaps there's something more you need in your code, though I don't know what. – CommonsWare Jun 14 '15 at 13:27

1 Answers1

0

As @CommonsWare pointed out, what you are doing should be OK. It is impossible to guarantee disabled auto-capitalization across all devices.

If the user is using a third-party keyboard, like SwiftKey, it may override disabling auto-capitalization; the user would have to manually do this in the third-party app settings.

Jared Rummler
  • 37,824
  • 19
  • 133
  • 148