Can I underline text in an android layout?android


You can try with

textview.setPaintFlags(textview.getPaintFlags() |   Paint.UNDERLINE_TEXT_FLAG);


How can I define underlined text in an Android layout xml file?

How to create a Textview with underline text in android

add this line to your code

textView.setPaintFlags(textView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);

Underline and change text color in Android TextView

Try this way to create underline

    <string name="your_string">
        This is an <u>underline</u>.


TextView tv = (TextView) view.findViewById(;
SpannableString content = new SpannableString("Content");
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);

OR using paint

txt.setPaintFlags(txt.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);

How to give underline to textview

This works for me:

    <string name="your_string"><u>underline</u></string>


You can add a separate view below your text view, enclose both of them in a linear or relative layout & set the width of the enclosing view to the width of the textview.