You can define the underlined text in an Android layout XML using a String Resouce XML file. In a string res file you have to use an HTML underline tag <u> </u> .
Once the feature is enabled you long hold over the text you want to underline. Then tap the button showing a “U” which stands for underline. This will underline the highlighted portion of your text message.
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)));
First of all, go to String.xml file
you can add any HTML attributes like , italic or bold or underline here.
<resources>
<string name="your_string_here">This is an <u>underline</u>.</string>
</resources>
You can use the markup below, but note that if you set the textAllCaps
to true
the underline effect would be removed.
<resource>
<string name="my_string_value">I am <u>underlined</u>.</string>
</resources>
Note
Using textAllCaps with a string (login_change_settings) that contains markup; the markup will be dropped by the caps conversion
The textAllCaps text transform will end up calling toString on the CharSequence, which has the net effect of removing any markup such as . This check looks for usages of strings containing markup that also specify textAllCaps=true.
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