How to programmatically disable smart text (without EditText)

There is an Android application containing a home-made input field (without TextViewor EditText), so I have to show / hide the keyboard, process user input and display the entered characters myself.

I need to disable predictive text mode for standard view. Unfortunately, the Android Viewclass (android.view.View) has no function setInputType.

There is a likely solution. Get InputConnectionthis view and change its properties. But I can not find how to get and install an instance of the current one InputConnection, unfortunately, the function onCreateInputConnectionis not called either.

Is there a way to disable predictive text mode for standard view?

+5
source share
2 answers

Something I used below is the "textNoSuggestions" tag, which I think will work for you!

<EditText android:layout_marginLeft="10px" 
android:layout_width="fill_parent"
android:layout_height="wrap_content" 
android:layout_marginRight="10px"
android:id="@+id/setupactivity_ftpsite" 
android:inputType="textNoSuggestions|textUri">
+5
source

Sorry, here is the answer in a more concise way.

Something like this:

1) show keyboard:

InputMethodManager imm =  (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(myCustomView, InputMethodManager.SHOW_IMPLICIT);

2) in myCustomView (extends the view), add:

 InputConnection onCreateInputConnection (EditorInfo outAttrs) {
     InputConnection ic = new EditableInputConnection(this);
     outAttrs.inputType = TYPE_TEXT_FLAG_NO_SUGGESTIONS;
     outAttrs.initialCapsMode = ic.getCursorCapsMode(outAttrs.inputType); //guess on this
     return ic;
}

This is the general essence of what needs to be done. You might want OR outAttrs.inputType instead of set to equal to keep the default state or first call the parent onCreateInputConnection and then just set your outAttrs.inputType (not sure if this will work or not). This will hopefully help you get closer to your decision.

+2
source

All Articles