Android的:如何添加下划线在字符串 [英] android: how to add Underline in the String

查看:300
本文介绍了Android的:如何添加下划线在字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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?

推荐答案

使用 SpannableString ,通过它可以做下划线,罢工,高亮,粗体,斜体等文本

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

为下划线,你必须使用 UnderlineSpan http://developer.android.com/reference/android/text/style/UnderlineSpan.html

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);

或只需添加HTML标记的资源字符串&LT;字符串名称=样品&GT; &LT; U&GT;数据&LT; / U&GT;&LT; /串&GT;

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

这篇关于Android的:如何添加下划线在字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆