Underlining text in TextView
As we all know there is a property called android:textStyle to set text as Bold and Italic. But it doesn’t have any value like underline. What if we want underlined text in android?
1st Approach
1 2 3 4 |
String data="Underlined Text"; SpannableString content = new SpannableString(data); content.setSpan(new UnderlineSpan(), 0, data.length(), 0); textView.setText(content); |
2nd Approach
1 2 3 |
String data="Underlined Text"; textView.setPaintFlags(textView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); textView.setText(data); |
3rd Approach
1 2 |
String htmlData="<u>Underlined Text</u>"; textView.setText(Html.fromHtml(htmlData)); |