开发者

How can I turn off suggestions in EditText?

开发者 https://www.devze.com 2023-01-17 17:24 出处:网络
How can I 开发者_开发百科turn off suggestions in EditText in Android?android:inputType=\"textNoSuggestions\"

How can I 开发者_开发百科turn off suggestions in EditText in Android?


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"


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


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.


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"


This is what worked for me:

android:importantForAutofill="no"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号