首页 > 解决方案 > TextView 链接下划线问题

问题描述

任何想法为什么链接上的下划线会超过链接之前的空格字符?您可以看到下划线几乎触及链接之前的字符 r 和 d。

在此处输入图像描述

我的文本视图:

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="5dp"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="15dp"
        android:text="@string/register_terms"
        android:textAlignment="center"
        android:textColor="#BFFFFFFF"
        android:textColorLink="@android:color/white"
        android:textSize="15sp" />

我的字符串:

<string name="register_terms">By clicking this button, you agree to our <a href="https://www.google.com/">Terms &amp; Conditions</a> and <a href="https://www.google.com/">Privacy Policy</a>.</string>

标签: androidtextview

解决方案


您可以在 xml 中将字符串编写为:

<string name="register_terms">By clicking this button, you agree to our&#160;<a href="https://www.google.com/">Terms &amp; Conditions</a> and <a href="https://www.google.com/">Privacy Policy</a>.</string>

并在 textview 属性中声明为:android:text="@string/register_terms"

或者您可以将 xml 中的字符串声明为:

<string name="register_terms">By clicking this button, you agree to our <![CDATA[<a href="https://www.google.com/">Terms &amp; Conditions</a>]]> and <![CDATA[<a href="https://www.google.com/">Privacy Policy</a>]]>.</string>

并在活动中用作:

    TextView textView = (TextView) findViewById(R.id.textView);
    textView.setText(Html.fromHtml(getString(R.string.register_terms)));

推荐阅读