按下时如何更改链接的文本颜色(触摸或按下效果)。请在下面查看我的代码
代码:
SpannableString spanStr = new SpannableString(tag);
spanStr.setSpan(new HashTagsClickableSpan(tag), 0, tag.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spanStr.setSpan(new ForegroundColorSpan(Color.RED),0,tag.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
class HashTagsClickableSpan extends ClickableSpan{
String clicked;
public HashTagsClickableSpan(String string) {
super();
clicked =string;
}
public void onClick(View tv) {
Toast.makeText(getActivity(), "Text = " + clicked,Toast.LENGTH_SHORT).show();
}
@Override
public void updateDrawState(TextPaint ds) {
ds.setUnderlineText(false);
}
}