Disabling autosuggestion on WebView?

前端 未结 8 987
盖世英雄少女心
盖世英雄少女心 2020-12-10 11:13

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 th

相关标签:
8条回答
  • 2020-12-10 11:41

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

    WebView.getSettings().setSavePassword(false);
    WebView.clearFormData();
    
    0 讨论(0)
  • 2020-12-10 11:46

    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
        }
    }
    
    0 讨论(0)
提交回复
热议问题