41

How can I turn off suggestions in EditText in Android?

rmtheis
  • 5,992
  • 12
  • 61
  • 78
James
  • 13,891
  • 26
  • 68
  • 93

8 Answers8

117
android:inputType="textNoSuggestions"

according to this, may or may not be supported by the IME (the keyboard).

However, this seems to work more often

android:inputType="textNoSuggestions|textVisiblePassword"
Csongor Kiss
  • 715
  • 6
  • 11
Kurru
  • 14,180
  • 18
  • 64
  • 84
  • 3
    `android:inputType="textNoSuggestions|textVisiblePassword"` did the trick for my Wildfire and Desire HD. Tx! – JOG Oct 31 '11 at 10:08
  • @Kurru: This works, but I get an ugly NullPointerException crash when trying 'event.getKeyCode()'. – Luis A. Florit Nov 09 '12 at 00:20
  • 7
    Please note, this will cause an issue with Swype keyboards. The space will not automatically add it self after a word has been "swyped". Also, the voice to text feature will not work as the feature is disabled since the Swype keyboard see this as a "password field". – Donn Felker Jul 11 '13 at 18:27
  • 1
    It seems that `textVisiblePassword` also causes problems with Japanese keyboards. Any idea on that one? – Georg Aug 17 '15 at 11:14
  • 2
    This also breaks the characters cap functionality – desgraci Aug 09 '19 at 07:33
  • And it breaks the stylus input on tablets too because it "explicilty tells software keyboard, that content of this field should not be added to any vocabulary, synchronized through network, added to usage statistics or anything like this" [source](https://stackoverflow.com/a/61592084/1014048) – Ivan Mir Oct 23 '20 at 00:53
32

It's already described in the link Yoni Samlan posted. You should read the documentation correctly ;)

There is a method called setInputType. All you need is to call it with

edittext.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
Tseng
  • 61,549
  • 15
  • 193
  • 205
  • 4
    Not supported on the HTC Desire – Kurru Mar 03 '11 at 23:50
  • 13
    Strange thing, on my Desire and Wildfire when setting android:inputType="textNoSuggestions" in xml it does not work. Setting it in the code work like a charm mEditText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); No problem with my Droid with the two methods. – ol_v_er Mar 15 '11 at 17:31
  • 2
    @ol_v_er: neither solution works for me, in a Galaxy Note with Hacker's keyboard. – Luis A. Florit Nov 09 '12 at 00:14
  • @LuisA.Florit input type flag is a flag to the keyboard, it's up to the implementation of the keyboard to do the right thing with it. – Dandre Allison May 05 '13 at 15:40
  • 2
    Important thing is to NOT `or` it with `TYPE_CLASS_TEXT` otherwise it kept overriding the 'no suggestions' flag. – scorpiodawg Feb 11 '15 at 08:45
17

This seems to work better;

edittext.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);

i.e. the visible password and no suggestion input types are OR'd together

To make sure you can also add this attribute to your edit text

android:inputType="textNoSuggestions|textVisiblePassword"
Mark
  • 245
  • 4
  • 10
6

android:inputType="textNoSuggestions". See the xml attribute documentation and this Android developers blog post.

Yoni Samlan
  • 37,905
  • 5
  • 60
  • 62
  • Thankyou for your answer. But i an dynamically reating the edittext i want to do the same in java code.Please help me. – James Sep 25 '10 at 05:15
  • Tseng above has it right -- most Android xml-settable attributes have matching set[attributeName] methods, in this case setInputType. – Yoni Samlan Sep 27 '10 at 15:18
2

If you are using InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS in activity, it will work fine. In case of DialogFragment, you should place InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS at onActivityCreated() handler as below:-

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    EditText editTextUsername =  (EditText)dialogView.findViewById(R.id.txtUsername);
    editTextUsername.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
}
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Shalu T D
  • 3,921
  • 2
  • 26
  • 37
1

use the next workaround - I noticed that when sending Email messages no suggestion appear-

android:inputType="textCapSentences|textNoSuggestions|textEmailAddress"

It is not 100% but it is working :)

Elad Gelman
  • 1,182
  • 1
  • 13
  • 27
1

If Editext/TextInputEditText has more than 1 line then add textMultiLine

 android:minLines="10"
 android:inputType="textNoSuggestions|textMultiLine|textVisiblePassword"
Aklesh Singh
  • 917
  • 10
  • 12
0

This is what worked for me:

android:importantForAutofill="no"
francis
  • 3,852
  • 1
  • 28
  • 30
  • This flag is related to the Autofill framework (for usernames and passwords), not to text suggestions. – Remc4 Apr 17 '23 at 13:25
  • You're right @Remc4. You can use `android:inputType="textNoSuggestions"` for text suggestions. – francis Apr 17 '23 at 20:34
  • Surprisingly that makes no difference. That's why everyone also adds textVisiblePassword flag. – Remc4 Apr 20 '23 at 16:23