String url = data.blockChainUrl; //https or http url
SpannableStringBuilder builder = new SpannableStringBuilder("");
int start = builder.length();
String content = mContext.getResources().getString(R.string.block_chain_query); //填充字体颜色
builder.append(content);
int end = builder.length();
builder.setSpan(new URLSpanNoUnderline(url) {
@Override
public void onClick(View widget) {
super.onClick(widget);
}
}, start, end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
builder.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.color_a5ef44)), 0,
end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
mBlockChainQuery.setText(builder);
//必须有的set mBlockChainQuery.setMovementMethod(LinkMovementMethod.getInstance());
//自定义一个URLSpan
class URLSpanNoUnderline extends URLSpan {
public URLSpanNoUnderline(String url) {
super(url);
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
//you self
}
}
原文地址:http://blog.51cto.com/360douruanliang/2147786