Android 给TextView的内容 添加跳转无下划线
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android 给TextView的内容 添加跳转无下划线相关的知识,希望对你有一定的参考价值。
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
}
}
以上是关于Android 给TextView的内容 添加跳转无下划线的主要内容,如果未能解决你的问题,请参考以下文章