9

I'm trying to disable predictive text for a given EditText, as explained here, but I still get the autocomplete by the prediction...

I've got a Samsung Galaxy S with XT9 enabled.

Anybody can help?

<EditText
    android:id="@+id/search_field"
    android:layout_width="300dp"
    android:layout_height="27dp"
    android:background="@drawable/bg_searchfield"
    android:hint="@string/search_hint"
    android:imeOptions="actionSearch"
    android:inputType="text|textNoSuggestions|textFilter"/>
Community
  • 1
  • 1
jul
  • 36,404
  • 64
  • 191
  • 318

5 Answers5

25

A comment from this SO question suggests that the xml attribute doesn't work for some models, but that the java-method does work in these cases. So try this:

edittext.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

edit:

As suggested in the comment below, here's an xml alternative that has worked:

android:inputType="textNoSuggestions|textVisiblePassword"
Community
  • 1
  • 1
keyser
  • 18,829
  • 16
  • 59
  • 101
7
android:inputType="textNoSuggestions|textVisiblePassword"

This solution works but you have to be careful with it. You cannot switch keyboard language on HTC devices (probably the reason is in Sense keyboard) if the flag textVisiblePassword is set.

So I had to set InputType from the code and to write something like this:

    public static int getInputTypeForNoSuggestsInput() {
    if (android.os.Build.MANUFACTURER.equalsIgnoreCase("Samsung")) {
        return InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
                | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
    } else {
        return InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
    }
macros013
  • 739
  • 9
  • 10
2

The only solution that worked for me to see the right font on hint and on text using the Calligraphy library is:

  • Set your password EditText in your xml with android:inputType="textNoSuggestions|textVisiblePassword"
  • Configure your EditText programmatically with: passwordET.transformationMethod = PasswordTransformationMethod()

This will:

  1. Show the correct font on hint
  2. Show the correct font on text
  3. Show the correct font if you've got a TextInputLayout
  4. Will not show suggestion or predictions in your keyboard.
Rafael Ruiz Muñoz
  • 5,333
  • 6
  • 46
  • 92
1

Most of the solutions given above didnt work for me. So I did a workaround.

Create a InputFilter with the below in the filter method:

for (char ch:BLOCKED_CHARACTER_SET.toCharArray()){
                if (source != null && source.toString().contains(ch+"")) {
                    return "";
                }
            }

Here BLOCKED_CHARACTER_SET is a string which contains the characters which we wanna block.

Then set the edittext

editText.setFilters(new InputFilter[]{filterUsername, new InputFilter.LengthFilter(LENGTH)});
sanjeeb
  • 87
  • 1
  • 12
0

If you need this for password field and still need characters masking:

inputType = InputType.TYPE_TEXT_VARIATION_PASSWORD or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
transformationMethod = PasswordTransformationMethod()
Fedir Tsapana
  • 1,283
  • 16
  • 19