Android: Styling inline html link in TextView

Viewed 1302

I have a TextView with some html text containing a link. I added a style to the TextView and now the link is not visible as a link.

The string:

<string name="strPrivacyPolicyAndContact">See our %1$s Privacy Policy %2$s or contact us for more information: support@beatrixkiddo.com.</string>

The TextView xml:

<TextView
    android:id="@+id/privacyAndContact"
    style="@style/NewFont_Label"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:gravity="left"
    android:text="@string/strPrivacyPolicyAndContact" />

The NewFont_Label style:

<style name="NewFont_Label">
    <item name="android:textSize">12sp</item>
    <item name="variant">medium</item>
    <item name="android:textColor">@color/label</item>
    <item name="android:textAllCaps">true</item>
    <item name="android:letterSpacing">0.02</item>
</style>

The code:

private static final String PRIVACY_HREF = "<a href=\"http://www.beatrixkiddo.com\privacy\">";
private static final String END_TAG = "</a>";

privacyAndContact = (TextView) view.findViewById(R.id.privacyAndContact);
privacyAndContact.setText(Html.fromHtml(getString(R.string.strPrivacyPolicyAndContact, PRIVACY_HREF, END_TAG)));

Before adding the style:

enter image description here

After adding the style:

enter image description here

The question:

I've tried adding all possible html tags with no result.
How do I style the link with an underline or a color?

Update

I've tried SpannableString, but it's impact is being annulled by the applying of the style on the TextView:

SpannableString privacy = new SpannableString(getString(R.string.strPrivacyPolicyAndContact));
privacy.setSpan(new URLSpan("http://www.beatrixkiddo.com/privacy"), 13, 26, 0);
privacy.setSpan(new UnderlineSpan(), 13, 26, 0);
privacy.setSpan(new ForegroundColorSpan(Color.RED), 13, 26, 0);
privacyAndContact.setText(privacy);

So the spannable doesn't work in this case either.

1 Answers
Related