How to remove Android auto-suggest underlining in

2019-04-27 03:53发布

问题:

I'm using an EditText to write some text. Android's auto-suggest underlines the word, until we hit space. Now, if I enter the word without the space, the resulting text has an underline. It's because I use Html.toHtml(view.getText()).

Now, there are a few answers I'll be expecting such as disabling auto-suggestion or using view.getText().toString(), but I need them both. I need the auto-suggestion feature as well as the formatting of the text. An example which solves this problem is the Gmail app. You can write whatever you want in the EditText box and it sends the email without the words being underlined.

回答1:

Use this just before you getText(). This is the most straightforward and the official way.

 edittext.clearComposingText();


回答2:

Do it like this

android:inputType="text|textNoSuggestions"  


回答3:

I just came up with a solution for this. After submitting the text, just hide the keyboard, and the text underline goes away.