Issue
I try to make a TextView as hyperlink. This one worked as expected :
content.text = "<a href=${args.article.url}>Content</a>".fromHtml()
But I get a lint warning regarding using string resources. But this one does now show TextView as hyperlink:
content.text = getString(R.string.content, args.article.url).fromHtml()
And this is String resource :
<string name="content"><a href="%s">Content</a></string>
Is there any solution to fix it using String resource?
@Suppress("DEPRECATION")
fun String.fromHtml() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(this, Html.FROM_HTML_MODE_COMPACT)
} else {
Html.fromHtml(this)
}
Solution
This is how to set text in TextView :
content.text = TextUtils.expandTemplate(getText(R.string.content), args.article.url).toString().fromHtml()
And this is how to set String resources :
<string name="content"><![CDATA[ <a href="$s">Content</a>]]></string>
Answered By - Ali
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.