Android 给TextView的内容 添加跳转无下划线

【Android 给TextView的内容 添加跳转无下划线】白日放歌须纵酒,青春作伴好还乡。这篇文章主要讲述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); //youself } }


    推荐阅读