Android 如何在TextView中为特定文本加下划线?

Android 如何在TextView中为特定文本加下划线?,android,android-layout,android-edittext,Android,Android Layout,Android Edittext,从以上代码中,我需要强调以粗体突出显示的服务条款和隐私政策 我尝试过使用,但没有成功 此外,我还需要增加服务条款的字体,仅限隐私政策 请给出一些建议。您需要在strings.xml文件中定义文本。是的,您也可以在其中定义格式化的html <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin

从以上代码中,我需要强调以粗体突出显示的服务条款和隐私政策

我尝试过使用
,但没有成功


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


请给出一些建议。

您需要在
strings.xml
文件中定义文本。是的,您也可以在其中定义格式化的html

<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"
    />
因此,您可以尝试以下方法:

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

单击“注册”表示您已经阅读并同意了
服务条款和隐私政策 ]]>
然后,在代码中:

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


这是最干净的方式。在Hallah。

检查这一点,我还需要增加服务条款的字体,仅限隐私政策
<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>