Search code examples
androidtextview

How to set underline text on textview?


How to set underline text on textview?

I have used following code but it is not working.

tvHide.setText(Html.fromHtml("<p><u>Hide post</u></p>").toString());

Solution

  • You have to use SpannableString for that :

    String mystring=new String("Hello.....");
    SpannableString content = new SpannableString(mystring);
    content.setSpan(new UnderlineSpan(), 0, mystring.length(), 0);
    yourtextview.setText(content);
    

    Update : You can refer my answer on Underling TextView's here in all possible ways.