59

I want to turn off displaying "Suggested Words" on the soft/virtual keyboard when someone is using my application (only on certain Activities). For the default Android keyboard, this can be found under 'Settings' (under Word Suggestion Settings).

Is there a way to disable it only within your application, without requiring the user to manually go and do it? I basically want the user to type words without providing any hints.

Thanks!

Thira
  • 1,555
  • 1
  • 13
  • 24
  • duplicate http://stackoverflow.com/questions/3789905/how-can-i-turnoff-suggestions-in-edittext – bancer Sep 13 '13 at 20:36

10 Answers10

66

When developing for 2.0+, the supposed way is setting android:inputType="textNoSuggestions" (ref). Unfortunately, suggestions are still shown on HTC Desire 2.2 (and probably other HTC Sense devices as well).
Using android:inputType="textVisiblePassword"will not help as well as the software keyboard by HTC won't allow you to switch languages.
So I stick to android:inputType="textFilter" to disable suggestions.

Sebastien FERRAND
  • 2,110
  • 2
  • 30
  • 62
yanchenko
  • 56,576
  • 33
  • 147
  • 165
  • 1
    I haven't tried using "android:inputType="textFilter", but I can also confirm that with multi-lined EditText controls on HTC Hense (using HTC Hero with a 2.1 ROM) "android:inputType="textVisiblePassword" doesn't work. It does work when the EditText is NOT multi-lined. Thanks! – Thira Dec 21 '10 at 04:05
  • for HTC Desire x, "android:inputType="textFilter" worked. Thanks – alicanbatur Apr 18 '14 at 06:47
  • 3
    "textVisiblePassword" disable Emoji, I can't use that. I have remove suggestions with android:inputType="textNoSuggestions" and android:privateImeOptions="nm" (nm : No Micro) – fingerup Feb 11 '15 at 18:06
  • 1
    didn't work for me. what worked was @AmeyaPandilwar's answer: `android:inputType="textNoSuggestions|textVisiblePassword"` – shoe Nov 07 '16 at 19:54
  • 1
    How can this simple function be so stupidly implemented. – Vincent Oct 09 '18 at 07:48
35

You can disable suggestions on the Soft Keyboard by adding the following line in the xml -

android:inputType="textNoSuggestions"

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

If this issue occurs, the below method works for sure -

android:inputType="textNoSuggestions|textVisiblePassword"
Ameya Pandilwar
  • 2,638
  • 28
  • 28
13

On my 6P running Nougat, nothing worked. While it is empty the suggestion bar stays up because it has the microphone icon on the right side. In order to get rid of that, I used fingerup's suggestion in one of the comments and it worked! So I decided to write an actual answer so people don't miss it. To recap here's what I've used:

    android:inputType="textNoSuggestions|textFilter|textVisiblePassword"
    android:privateImeOptions="nm"

inputType="textNoSuggestions|textFilter|textVisiblePassword" prevents suggestions, and privateImeOptions="nm" (stands for "no microphone") prevents the bar from showing up because it still would since the mic button is in it. So it is necessary to use both attributes because if all you do is specify no mic then the bar still shows up with recommendations.
Thx again to fingerup for mentioning the nm trick. ;)

Francois Dermu
  • 4,437
  • 2
  • 22
  • 14
13

This works for me with the stock keyboard, even on HTC with 2.2

final EditText et = (EditText) findViewById(R.id.SearchText);
et.setInputType(et.getInputType()
    | EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS
    | EditorInfo.TYPE_TEXT_VARIATION_FILTER);
SoftWyer
  • 1,986
  • 28
  • 33
  • 2
    I would like to add a wrinkle that I ran into. OR-ing those flags to the existing inputType may not work. In my case on a Samsung Galaxy SIII running 4.04, the existing inputType was EditorInfo.TYPE_CLASS_TEXT when it was inflated. OR-ing the additional flags did not prevent the suggestions. However, if I set the inputType just to EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS, that successfully prevented suggestions: et.setInputType(EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS); Hope this helps. – Craig B Mar 06 '13 at 20:09
6

There are two ways that I know of to disable the auto-complete. One way is through the XML by setting the android:inputType="textVisiblePassword" in the layout xml.

The other way is through code such as the following

EdtiText editTextBox = findViewById(R.id.myEditTextView);
editTextBox.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
dlongest
  • 462
  • 3
  • 3
  • 4
    You cannot disable suggestions for password field like this. It is better to use EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS – Vadym Stetsiak Mar 23 '11 at 02:54
6

I was facing the same issue on Samsung devices using:

android:inputType="textNoSuggestions|textFilter|textVisiblePassword"

only after setting the inputType to password and visiblePassword worked for me:

android:inputType="textPassword|textVisiblePassword"
Oush
  • 3,090
  • 23
  • 22
2

hope this works for you,

editText.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_CAP_SENTENCES|InputType.TYPE_TEXT_FLAG_MULTI_LINE|InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
Harshal Benake
  • 2,391
  • 1
  • 23
  • 40
1

android:inputType="textPhonetic" hides soft keyboard suggestions on Android 1.6.

bancer
  • 7,475
  • 7
  • 39
  • 58
1

Use android:inputType="textVisiblePassword"

  • 1
    Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? **If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient.** Can you kindly [edit] your answer to offer an explanation? – Jeremy Caney Aug 31 '23 at 01:57
0

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);
}
Shalu T D
  • 3,921
  • 2
  • 26
  • 37