Search code examples
androidtextviewantialiasing

Underlined TextView is not anti-aliased


When trying to make text underlined:

setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);

TextView becomes non anti-aliased. If I enable anti-aliasing:

getPaint().setAntiAlias(true)

Then it becomes anti-aliased.

Is there some connection between anti-aliasing and Paint.UNDERLINE_TEXT_FLAG?

enter image description here


Solution

  • There is no connection betwenn anti-aliasing and Paint.UNDERLINE_TEXT_FLAG .

    But the difference is that setPaintFlags(Paint.UNDERLINE_TEXT_FLAG) will remove default existing flags & set the current flag as Paint.UNDERLINE_TEXT_FLAG only. Try the below code to keep existing flags & add new flag

    yourTextView.setPaintFlags(yourTextView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);