23

I have some HTML text inputs into a WebView, and I need to disable the autosuggetions on these inputs from Android, not from HTML (autocomplete=off).

How can I do this?

Mat
  • 202,337
  • 40
  • 393
  • 406
Buda Florin
  • 624
  • 2
  • 12
  • 30
  • here is the main link [http://stackoverflow.com/questions/582244/is-there-a-w3c-valid-way-to-disable-autocomplete-in-a-html-form][1] [1]: http://stackoverflow.com/questions/582244/is-there-a-w3c-valid-way-to-disable-autocomplete-in-a-html-form –  Sep 22 '11 at 16:02

8 Answers8

33

This problem vexed me for quite a while but the solution is very simple:

webview.getSettings().setSaveFormData(false);

I wrote about it here:

http://roysutton.com/2012/02/21/preventing-auto-fill-in-android-webview/

Pre101
  • 2,370
  • 16
  • 23
16

The suggested above answers didn't help me. So I found next solution: I just created a simple wrapper for WebView and used it.

public class NoSuggestionsWebView extends WebView {
    public NoSuggestionsWebView(Context context) {
        super(context);
    }

    public NoSuggestionsWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NoSuggestionsWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
        InputConnection ic = super.onCreateInputConnection(outAttrs);

        outAttrs.inputType &= ~EditorInfo.TYPE_MASK_VARIATION; /* clear VARIATION type to be able to set new value */
        outAttrs.inputType |= InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD; /* WEB_PASSWORD type will prevent form suggestions */

        return ic;
    }
}
lpsun
  • 267
  • 2
  • 11
5

In addition to setSaveFormData setting as False, this also helped me

WebView.getSettings().setSavePassword(false);
WebView.clearFormData();
Mark Coleman
  • 40,542
  • 9
  • 81
  • 101
Kamal
  • 5,462
  • 8
  • 45
  • 58
2

None of the above helped so after extensive search i found this which works perfect on webview as well as normal websites. Text area can be replaced by Input text fields too :)

<textarea class="form-control" id="comments" autocomplete="off" autocorrect="off"  spellcheck="false"></textarea>
2

A solution of @lpsun in Kotlin.

import android.content.Context
import android.text.InputType
import android.util.AttributeSet
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputConnection
import android.webkit.WebView

class NoSuggestionsWebView : WebView {
    constructor(context: Context) : super(context)

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs)

    constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs,
        defStyle)

    override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection? {
        val ic = super.onCreateInputConnection(outAttrs)

        /* clear VARIATION type to be able to set new value */
        outAttrs.inputType = outAttrs.inputType and EditorInfo.TYPE_MASK_VARIATION.inv()
        /* WEB_PASSWORD type will prevent form suggestions */
        outAttrs.inputType = outAttrs.inputType or InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD

        return ic
    }
}
CoolMind
  • 26,736
  • 15
  • 188
  • 224
  • For Android 5 without Google Play Services see https://stackoverflow.com/questions/41025200/android-view-inflateexception-error-inflating-class-android-webkit-webview/60639991. There is a bug in `appcompat` library, so WebView will crash on these devices. – CoolMind Mar 27 '20 at 07:45
1

If it already has the form data then setSaveFormData(false) won't stop it from using it. To clear the database you may have to do the following:

WebViewDatabase.getInstance(this).clearFormData();

Hugh Jeffner
  • 2,936
  • 4
  • 32
  • 31
0

I couldn't do this from Android's side, however in adding to the webview's text input spellcheck="false" did the trick.

<textarea spellcheck="false"></textarea>
Sami
  • 669
  • 5
  • 20
0

In Android 8 and above, you should set importance of a textview subclass for system auto-fill feature:

android:importantForAutofill="noExcludeDescendants"

Official reference: Optimize your app for autofill

Furthermore, You might try to delete the "Web Data" sqlite file in data/data/{your-app-package}/app_webview when webview isn't in use for security's sake.

Shrdi
  • 359
  • 4
  • 13