I have this value in string.xml file:
<string name="rights">Copyright © All Rights Reserved %1$d <b> <a href="http://www.example.com/">company name</a></b></string>
And I have applied this code that pass to the above text & set that text to the TextView
private void setupAppInfoRights() {
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
String rights = String.format(new Locale("en"), getString(R.string.rights), currentYear);
appInfoRights.setText(rights);
appInfoRights.setMovementMethod(LinkMovementMethod.getInstance());
}
When I remove the passed value everything goes fine & when the user click on the company name it takes him/her to the company website.
Please note that I have tried autoLink in xml when there is no value passed but it does not work as expected.
But, when I add the passed value & used the code above the company name has no underline & when the user clicks it , it will do nothing.
How to edit my above code to pass the current year & keep the link behavior normal?
Note: I have used String.format
to display the current year as English number always despite the other locale numbers.
I think
SpannableStringBuilder
is what you are looking for.If you want to make only certain part clickable then toggle the values of
0
andspan.length()
insetSpan()
.