我有像下面这样的 spanableString
TextView contentNews = findViewById(R.id.text)
.........
.........
//article.getP() is HTML string
.........
CharSequence sequence = Html.fromHtml(article.getP(), this, null);
SpannableString spannableString = new SpannableString(sequence);
Linkify.addLinks(spannableString, Linkify.ALL);
URLSpan[] urlSpans = spannableString.getSpans(0, spannableString.length(), URLSpan.class);
for(URLSpan span : urlSpans){
Timber.d("LINK SPAN %s",span.getURL());
int start = spannableString.getSpanStart(span);
int end = spannableString.getSpanEnd(span);
int flag = spannableString.getSpanFlags(span);
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick( View widget) {
Toast.makeText(NewReadingActivity.this, "Click " + span.getURL(), Toast.LENGTH_SHORT).show();
}
};
spannableString.setSpan(clickableSpan, start, end, flag);
}
contentNews.setText(spannableString);
但是当我点击它什么也没做时,Log Timber 还设法找到如下 URL:
01-16 20:42:55.560 mobile.android.tribun.daerah.jambi D/NewReadingActivity:418: LINK SPAN http://TRI-TIM.COM