How to set underline text on textview?
I have used following code but it is not working.
tvHide.setText(Html.fromHtml("
Android supports string formatting using HTML tags in the strings xml. So the following would work:
This text has an underscore
Then you just use it as you normally would. You can see more in the documentation here
Update:
To further expand on the answer, the documentation says:
... the
format(String, Object...)andgetString(int, Object...)methods strip all the style information from the string. . The work-around to this is to write the HTML tags with escaped entities, which are then recovered with fromHtml(String), after the formatting takes place
For example, the resulting string from the following code snippet will not show up as containing underscored elements:
This %1$s has an underscore
String result = getString(R.string.html_bold_test, "text")
However the result from the following snippet would contain underscores:
This <u> %1$s </u> has an underscore
String result = Html.fromHtml(getString(R.string.html_bold_test, "text"))