Tip : 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)); |
Ravi Rupareliya
He loves to explore new technologies and have worked on Android, React Native, Action on Google and Flutter.
Latest posts by Ravi Rupareliya (see all)
- Make Your Github Profile Dynamic - August 25, 2020
- Dialogflow Entities With Actions on Google - May 7, 2020
- Actions on Google Using Cloud Functions - February 3, 2020