EditText remove black underline while typing

2019-07-04 04:02发布

问题:

I have bit of an issue in my EditText.

I have a piece of code that detects when a specific piece of text is underlined (so that a underline icon can be highlighted). This is achieved by detecting UnderlineSpans. However when typing there are underlines under the current word, which appears to also use UnderlineSpans, therefore leading the underline icon being selected: https://i.stack.imgur.com/jBloM.jpg

I've already tried adding android:inputType="textNoSuggestions" to my EditText XML. However this appears to disable spell checking, but not the black underline. Is there anyway to remove this underline (preferably without removing spell checking) or an alternative for me to detect my own UnderlineSpans?

回答1:

Managed to fix it in my case. I created an empty UnderlineSpan class. e.g.

public class CustomUnderlineSpan extends UnderlineSpan {
}

I then used this in my span setting and detection code. This meant that all my additional underline spans were now using this class, so the icon was only selected when one of my custom underline spans is present. The underline from Android is still there, but it isn't a problem for me in this case.