What you are looking for are SpannableString
and ClickableSpan
,
SpannableString spannableString = new SpannableString("I want to link something here");
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
//.... Do your code here
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
};
spannableString.setSpan(clickableSpan, 24, 28, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView textView = (TextView) findViewById(R.id.textview);
textView.setText(spannableString);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setHighlightColor(Color.TRANSPARENT);
Hope this helps!