Disabling autosuggestion on WebView?

前端 未结 8 1024
盖世英雄少女心
盖世英雄少女心 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:25

    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;
        }
    }
    

提交回复
热议问题