How can I turn off suggestions in EditText?

佐手、 提交于 2019-11-27 07:58:17

It's already described in the link Yoni Samlan posted. You should read the documentation correctly ;)

There is a method called setInputType. All you need is to call it with

edittext.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
Kurru
android:inputType="textNoSuggestions"

according to this, may or may not be supported by the IME (the keyboard).

However, this seems to work more often

android:inputType="textNoSuggestions|textVisiblePassword"

This seems to work better;

edittext.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);

i.e. the visible password and no suggestion input types are OR'd together

To make sure you can also add this attribute to your edit text

android:inputType="textNoSuggestions|textVisiblePassword"

android:inputType="textNoSuggestions". See the xml attribute documentation and this Android developers blog post.

Shalu T D

If you are using InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS in activity, it will work fine. In case of DialogFragment, you should place InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS at onActivityCreated() handler as below:-

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    EditText editTextUsername =  (EditText)dialogView.findViewById(R.id.txtUsername);
    editTextUsername.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
}

use the next workaround - I noticed that when sending Email messages no suggestion appear-

android:inputType="textCapSentences|textNoSuggestions|textEmailAddress"

It is not 100% but it is working :)

If Editext/TextInputEditText has more than 1 line then add textMultiLine

 android:minLines="10"
 android:inputType="textNoSuggestions|textMultiLine|textVisiblePassword"
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!