How to set underline text on textview?
I have used following code but it is not working.
tvHide.setText(Html.fromHtml("
Following are the some approaches for underlined text in android:
1st Approach
You can define your string in strings.xml
Underlined text
And use that string in your xml file
Or you can use that string in your Activity/Fragment
txtView.setText(R.string.your_string);
2nd Approach
To underline the text in TextView, you can use SpannableString
String text="Underlined Text";
SpannableString content = new SpannableString(text);
content.setSpan(new UnderlineSpan(), 0, text.length(), 0);
txtView.setText(content);
3rd Approach
You can make use of setPaintFlags method of TextView to underline the text of TextView.
txtView.setPaintFlags(mTextView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
txtView.setText("Underlined Text");
4th Approach
Make use of Html.fromHtml(htmlString);
String htmlString="Underlined Text";
txtView.setText(Html.fromHtml(htmlString));
Or
txtView.setText(Html.fromHtml("underlined text"));
Note:
If you have added this line android:textAllCaps="true" in your layout, then none of the above will work. For that, you have to define your string in Caps and then any of the above approach.