android:如何在String中添加下划线

adi*_*dig 2 string android textview

<string-array name="myarray">    
<item>Apple</item> 
<item>Banana</item> 
<item>Grape</item>
<item>Melon</item>
Run Code Online (Sandbox Code Playgroud)

如果我想添加下划线"香蕉"我应该添加什么?

Moh*_*ikh 12

使用SpannableString下划线,打击,突出显示,粗体,斜体等文本

对于Underline,你必须使用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);
Run Code Online (Sandbox Code Playgroud)

或者只是通过向资源字符串添加HTML标记 <string name="sample"> <u>your data</u></string>