I have an app with lots of text that is in strings.xml. Parts of that text are hyperlinks that have to be clickable.
Now, when I insert that text into TextView from the layout file it works, but when I try to insert that same text into the same TextView with tv.settext(getStrings...) it won't work.
Here is the code:
strings.xml:
<string name="some_text">
For you to see the article, you need to click <a href='http://www.google.com'>this link</a>
\n\n
after that etc...
</string>
Activity:
TextView txt = findViewById(R.id.link_tv);
txt.setMovementMethod(LinkMovementMethod.getInstance());
txt.setText(getString(R.string.some_text));
activity_main.xml:
<TextView
android:id="@+id/link_tv"
android:textColor="@color/privacy_policy_link_text_color"
android:paddingLeft="@dimen/_5sdp"
android:paddingRight="@dimen/_5sdp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Any thoughts?
check below point before testing
http://
or https://
<string name="some_text"><![CDATA[PLACE_YOUR_HTML_STRING_HERE]]></string>
)manifest.xml
file <uses-permission android:name="android.permission.INTERNET"/>
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
textView.setText(Html.fromHtml(getString(R.string.html_string), Html.FROM_HTML_MODE_COMPACT));
} else {
textView.setText(Html.fromHtml(getString(R.string.html_string)));
}
Linkify.addLinks(textView, Linkify.ALL);
textView.setMovementMethod(LinkMovementMethod.getInstance());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With