How do you underline a text in Android XML? How do you underline a text in Android XML? android android

How do you underline a text in Android XML?


If you are using a string resource xml file (supports HTML tags), it can be done using<b> </b>, <i> </i> and <u> </u>.

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

If you want to underline something from code use:

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

Hope this helps


Use this:

TextView txt = (TextView) findViewById(R.id.Textview1);txt.setPaintFlags(txt.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);


<resource>    <string name="your_string_here">This is an <u>underline</u>.</string></resources>

If it does not work then

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

Because "<" could be a keyword at some time.

And for Displaying

TextView textView = (TextView) view.findViewById(R.id.textview);textView.setText(Html.fromHtml(getString(R.string.your_string_here)));