0

Any ideas why the underline on the links go over the space character just before the link? You can see the underline is almost touching the character before the link, r and d.

enter image description here

My TextView:

    <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" />

My string:

<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>
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
passatgt
  • 4,234
  • 4
  • 40
  • 54

2 Answers2

0

Here is a link to the answer that my help you: LINK.

They explain in details how to use CDATA in string to use HTML tags and use Html.fromHtml() method to set the text.

Here is an example:

Set the text using Html.fromHtml() in your Activity class.

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

In strings.xml modify as below:

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

Hope that helps :)

0

You can write your string in xml as :

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

And declare in textview property as : android:text="@string/register_terms"

Or you can declare string in xml as :

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

And use in activity as :

    TextView textView = (TextView) findViewById(R.id.textView);
    textView.setText(Html.fromHtml(getString(R.string.register_terms)));
Rozina
  • 409
  • 3
  • 14