62

My EditText needs to accept input consisting of partial words, names, etc. At least on my HTC Desire, this is difficult since the keyboard wants to suggest and/or correct some entries (e.g., changes "gor" to "for"). I tried setting textNoSuggestions on the view, but that doesn't fix it.

Any simple solution to this?

gordonwd
  • 4,537
  • 9
  • 37
  • 53

4 Answers4

71

Try this:

android:inputType="textFilter"

If that doesn't work, try:

android:inputType="textFilter|textNoSuggestions"
magicman
  • 1,199
  • 6
  • 8
  • 1
    Doesn't work on a Nexus 5 with the last version of the Google keyboard, but it works with `textVisiblePassword`. – manfcas Nov 16 '17 at 11:29
66

You can do this from the code. Set the input type of the EditText like below:

txtEmail = (EditText) findViewById(R.id.txtEmail);
txtEmail.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

For a list of all the available input type options see http://developer.android.com/reference/android/text/InputType.html

Nik Reiman
  • 39,067
  • 29
  • 104
  • 160
Zaki Choudhury
  • 1,497
  • 15
  • 6
38

The other suggestions are correct, but SwiftKey has decided it will ignore the inputtype values "in response to user requests". While I agree this is a bad idea since it contradicts the Google guidelines and developers usually have a good reason for disabling auto-correction (like username fields, family names and so on), it still is the most used keyboard application for Android devices, so this can be a big problem.

The workaround is to use either

android:inputType="textVisiblePassword"

or

.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
Vlad Schnakovszki
  • 8,434
  • 6
  • 80
  • 114
  • 2
    Then be prepared to have a problem with typeface monospace. :) – Léon Pelletier Jan 30 '14 at 15:59
  • 3
    Thank you for this! I confirm it works with Swiftkey, where the other solutions (textNoSuggestions and/or textFilter) did not. – BoD Jan 02 '15 at 19:43
  • @LéonPelletier: Please explain. – Nino van Hooff Mar 29 '16 at 14:31
  • Before API 16, you need to apply a transformation. On API 16+, you can set the font. Refer to http://stackoverflow.com/questions/3406534/password-hint-font-in-android Very old bug. Impact everything I've coded so far on Android when designing the Login screen. – Léon Pelletier Mar 29 '16 at 18:09
  • Swiftkey resists that and still capitalizes, but at least turns off suggestions in Swiftkey and also in Google keyboard... :( – Ferran Maylinch Apr 10 '16 at 16:50
  • @FerranMaylinch I am using Swiftkey and it *doesn't resist* `inputType="textVisiblePassword`, i.e. will not show prediction, if that's what you meant. Maybe you are using it together with other values. – Redoman Apr 11 '16 at 07:39
  • @jj_ Suggestions are turned off, yes. What it doesn't turn off is capitalization each time I start a new line. I will end up suggesting the user to switch to the stock keyboard while using my app because it's a coding app and those caps are really annoying. I see that other apps like DroidEdit suffer from the same issue. – Ferran Maylinch Apr 11 '16 at 08:35
  • @FerranMaylinch ah ok I see, thanks for making it clear. – Redoman Apr 11 '16 at 08:42
  • for swift key i use `android:inputType="textVisiblePassword|textCapSentences"` – stephen1706 Oct 13 '16 at 13:43
4

Try this if you want a multi-line EditText without displaying the underlines (auto correct):

    myEditText.setInputType(InputType.TYPE_CLASS_TEXT | 
       InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

Here's XML for that: android:inputType="textNoSuggestions|textMultiLine".

soshial
  • 5,906
  • 6
  • 32
  • 40
live-love
  • 48,840
  • 22
  • 240
  • 204