首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何给TextView中的特定文本加下划线?

如何给TextView中的特定文本加下划线?
EN

Stack Overflow用户
提问于 2013-02-12 18:06:25
回答 2查看 816关注 0票数 0
代码语言:javascript
复制
<TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="2dp"
        android:layout_marginLeft="10dp"
        android:text="Don&apos;t worry we will never share this with anyone\nBy Clicking register you are indicating that you have read and agreed to the \n **Terms of services**  and **Privacy Policy**"
        android:textColor="@android:color/black" 
        android:textSize="8.5sp"
    />

从上面的代码中,我需要在服务条款和隐私政策下划线,这些条款和隐私政策以粗体突出显示。

我试过使用<u></u>,但不起作用。

我还需要增加服务条款的字体,仅隐私政策

请一定要给我一些建议。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-02-12 18:14:53

你需要在strings.xml file.Yes中定义你的文本,你也可以在其中定义格式化的html。

所以你可以试试这个:

代码语言:javascript
复制
<string name="nice_html">
<![CDATA[Don&apos;t worry we will never share this with anyone<br/>
By Clicking register you are indicating that you have read and agreed to the <br/>
 <u>Terms of services</u>  and <u>Privacy Policy</u>
]]></string>

然后,在你的代码中:

TextView foo = (TextView)findViewById(R.id.foo); foo.setText(Html.fromHtml(getString(R.string.nice_html)));

Original answer

这是做it.Inshallah最干净的方法。

票数 1
EN

Stack Overflow用户

发布于 2013-02-12 18:12:13

代码语言:javascript
复制
String mString=new String("Don&apos;t worry we will never share this with anyone\nBy Clicking register you are indicating that you have read and agreed to the \n **Terms of services**  and **Privacy Policy**");
SpannableString span = new SpannableString(mString);
span.setSpan(new UnderlineSpan(), index of T in terms, mString.length(), 0);
mTextView.setText(span);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14829942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档