Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I underline text in an Android layout?

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

like image 237
Janusz Avatar asked Mar 07 '10 02:03

Janusz


People also ask

How do you set an underline for text?

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.

How do you underline text on a cell phone?

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.

How do you underline text in XML?

Just use <u> and <\u> in XML, and it's enough.

What is Spannable string in Android?

↳ 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 .


2 Answers

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); 
like image 191
Anthony Forloney Avatar answered Oct 12 '22 00:10

Anthony Forloney


You can try with

textview.setPaintFlags(textview.getPaintFlags() |   Paint.UNDERLINE_TEXT_FLAG); 
like image 44
vado Avatar answered Oct 12 '22 02:10

vado