Link color declared in string.xml (Versions below N)

0

I have the following declared text in string.xml :

<string name="TITLE_EXAMPLE"><![CDATA[
    <p>Para entrar em contato com nossa Central:</p>
    <p><b>Brasil: Capitais</b></p>
    <p> <a href="tel:+5541123123123" style="color:#E29800"> 5541123123123</a> </p>
    ]]>
</string>

How do I apply a certain color to ahref ?

Even with style is not working!

[EDIT]

At the suggestion of psr village :

TextView contact = findViewById(R.id.contact);

String html;
contact.setMovementMethod(LinkMovementMethod.getInstance());
    if (Build.VERSION.SDK_INT >= Build.VERSIONS_CODE.N) {
        html = Html.fromHtml(getString(R.string.codeHtml), FROM_HTML_OPTION_USE_CSS_COLORS);
    } else {
        html = Html.fromHtml(getString(R.string.codeHtml));
    }

    contact.setText(html);

Only works on versions of N up!

I would like to apply on all versions!

    
asked by anonymous 14.12.2017 / 20:35

1 answer

1

To use HTML in TextView or similar, you need to use the Html class, native to Android.

This class has a method called fromHtml a> that serves just this function.

In the case of a TextView, you can use the following code:

TextView textView = findViewById(R.id.textViewId);

String html;

if (Build.VERSION.SDK_INT >= Build.VERSIONS_CODE.N) {
    html = Html.fromHtml(getString(R.string.codeHtml), FROM_HTML_OPTION_USE_CSS_COLORS);
} else {
    html = Html.fromHtml(getString(R.string.codeHtml));
}

textView.setText(html);
    
14.12.2017 / 20:43