How can I define underlined text in an Android layout xml
file?
The quickest way to underline text is to press Ctrl+U and start typing. When you want to stop underlining, press Ctrl+U again. You can also underline text and spaces in several other ways.
Douple-tap to select the text and bring up the context menu, then press the right arrow. You'll see options to bold, italicize and underline your text. When editing text in any application, a two finger swipe to the left over the text will select the entire current paragraph.
Just use <u> and <\u> in XML, and it's enough.
↳ android.text.SpannableString. This is the class for text whose content is immutable but to which markup objects can be attached and detached. For mutable text, see SpannableStringBuilder .
It can be achieved if you are using a string resource xml file, which supports HTML tags like <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 textView = (TextView) view.findViewById(R.id.textview); SpannableString content = new SpannableString("Content"); content.setSpan(new UnderlineSpan(), 0, content.length(), 0); textView.setText(content);
You can try with
textview.setPaintFlags(textview.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With