【问题标题】:TextView link underline issue [duplicate]TextView链接下划线问题[重复]
【发布时间】:2018-05-01 09:43:43
【问题描述】:

知道为什么链接上的下划线会超过链接之前的空格字符吗?您可以看到下划线几乎触及链接之前的字符 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>

【问题讨论】:

    标签: android textview


    【解决方案1】:

    您可以在 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)));
    

    【讨论】:

      【解决方案2】:

      这是我帮助您的答案的链接:LINK

      他们详细解释了如何在字符串中使用CDATA来使用HTML标签并使用Html.fromHtml()方法来设置文本。

      这是一个例子:

      Activity 类中使用Html.fromHtml() 设置文本。

      TextView textView = (TextView) findViewById(R.id.textView);
      textView.setText(Html.fromHtml(getString(R.string.link)));
      textView.setMovementMethod(LinkMovementMethod.getInstance());
      

      在strings.xml中修改如下:

      <string name="link">Test <![CDATA[<a href="#">link</a>]]></string>
      

      希望有帮助:)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-02-26
        • 1970-01-01
        • 2017-07-09
        • 2012-05-15
        • 2019-06-17
        • 2021-01-26
        • 2010-10-28
        • 1970-01-01
        相关资源
        最近更新 更多