I want to make a link for a textview text like Google. Is there anyway to make link like this. (i.e) When clicking on the word Google it should open the appropriate link. An
Note :- Html.fromHtml is deprecated in Android N
You need to do check and support Android N and higher versions of Android
//Set clickable true
tagHeading.setClickable(true);
//Handlle click event
tagHeading.setMovementMethod(LinkMovementMethod.getInstance());
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
tagHeading.setText(Html.fromHtml("https://github.com/hiteshsahu", Html.FROM_HTML_MODE_LEGACY));
} else {
tagHeading.setText(Html.fromHtml("https://github.com/hiteshsahu"));
}
Alternatively
You can don't want to id programmatically add autoLink flag on TextView.
android:autoLink="web"
android:linksClickable="true"
This way You don't need to add tags.
Which is a disadvantage, if you want to add hyperlink on a text you can't do it this way. eg you can't do something like this:- [hiteshsahu][1]
The result from both approach:-
https://github.com/hiteshsahu