String htmlString="<u>This text will be underlined</u>";
String udata="Underlined Text";
SpannableString content = new SpannableString(udata);
content.setSpan(new UnderlineSpan(), 0, udata.length(), 0);
mTextView.setPaintFlags(mTextView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
mTextView.setText("This text will be underlined");
A third approach would be using Html.fromHtml("<u>This text will be underlined</u>"), but I have to admit I'm a much bigger fan of using SpannableStrings. @Kartik: You might as well use a StrikethroughSpan on the text to create the strikethrough effect. :)
For underling the text in TextView you have to use SpannableString
Glad to hear that..Mark this question as solved so that other users can refer it.
I know this is kinda old, but is there a way to set the thickness of the underline?
Let me explain you all approaches :
Love the 3rd approach. Short, simple and concise and adds just one extra line of code to my program.
There are three ways of underling the text in TextView.
You can make use of setPaintFlags method of TextView to underline the text of TextView.
You can refer constants of Paint class if you want to strike thru the text.