Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: how to add Underline in the String

<string-array name="myarray">    
<item>Apple</item> 
<item>Banana</item> 
<item>Grape</item>
<item>Melon</item>

if i want to add Underline the "Banana" what should I add?

like image 853
adig Avatar asked Apr 13 '12 07:04

adig


People also ask

How do you underline text in a string?

You can also underline a portion of the text via code, it can be done by creating a SpannableString and then setting it as the TextView text property: SpannableString text = new SpannableString("Voglio sottolineare solo questa parola");text. setSpan(new UnderlineSpan(), 25, 6, 0);textView. setText(text);

How do you underline TextView?

One line solution. myTextView. setText(Html. fromHtml("<p><u>I am Underlined text</u></p>"));

What is Spannable string in Android?

Text styling is one of the important aspects when it comes to enhancing the UI of an Android application. In Android, we can change the size, color, weight, style, etc of a text and make the text more attractive and appealing.


1 Answers

use SpannableString by which you can do Underline, Strike, Highlight, Bold, Italic etc to the text

for Underline you have to use UnderlineSpan http://developer.android.com/reference/android/text/style/UnderlineSpan.html

 TextView textview = (TextView)findViewById(R.id.textview);
 SpannableString content = new SpannableString("Apple Banana Grape Melon");
 content.setSpan(new UnderlineSpan(), 6, 11, 0);
 textview.setText(content);

or simply by adding HTML tag to the resource string <string name="sample"> <u>your data</u></string>

like image 144
Mohammed Azharuddin Shaikh Avatar answered Nov 04 '22 16:11

Mohammed Azharuddin Shaikh