Issue
I have created 3 strings in string resources. Every string has an external link in it. Basically I am trying to put one sentence in a TextView
which has 3 outside links in it. Please tell how to do this in Android.
If we can assign multiple string through XML only that will be best.
Solution
You have to use Spannable, here is example below, have a look
ClickableSpan linkClick = new ClickableSpan() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Link Click",
Toast.LENGTH_SHORT).show();
view.invalidate();
}
@Override
public void updateDrawState(TextPaint ds) {
if (textView.isPressed()) {
ds.setColor(Color.BLUE);
} else {
ds.setColor(Color.RED);
}
textView.invalidate();
}
};
textView.setHighlightColor(Color.TRANSPARENT);
Spannable spannableString = new SpannableString("Link in TextView");
spannableString.setSpan(linkClick, 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(spannableString, TextView.BufferType.SPANNABLE);
textView.setMovementMethod(LinkMovementMethod.getInstance());
In this, String Link in TextView
only "LINK" is clickable
Answered By - Sanwal Singh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.