我需要我的 ClickableSpan 来更改链接背景,当它们被触摸时。那是我的代码:
holder.text.setMovementMethod(LinkMovementMethod.getInstance());
holder.text.setText(addClickablePart(post.getTweet().getText()), BufferType.SPANNABLE);
private SpannableStringBuilder addClickablePart(String str) {
SpannableStringBuilder ssb = new SpannableStringBuilder(str);
int idx1 = str.indexOf("#");
int idx2 = 0;
while (idx1 != -1) {
idx2 = str.indexOf(" ", idx1);
if(idx2 == -1) {
idx2 = str.length();
}
final String clickString = str.substring(idx1, idx2);
ssb.setSpan(new ClickableSpan() {
@Override
public void updateDrawState(TextPaint ds) {
ds.setUnderlineText(false);
super.updateDrawState(ds);
}
@Override
public void onClick(View widget) {
if(clickString.startsWith("#")) {
Toast.makeText(getView().getContext(), "left",
Toast.LENGTH_SHORT).show();
}
}
}, idx1, idx2, 0);
idx1 = str.indexOf("#", idx2);
}
我不明白我怎么能把它拉下来......有什么想法吗?