android开发之TextView超链接无下划线

<pre name="code" class="java">				String msg = "感谢您的支持,发送您的建议或意见我们将尽快回复。\n点此查看《常见问题》。";
				SpannableStringBuilder style = new SpannableStringBuilder(msg);
				style.setSpan(new ForegroundColorSpan(Color.BLUE), 24, msg.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
				style.setSpan(new NoLineClickSpan("点此查看《常见问题》。"), 24, msg.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
				// msgContent.setText(style);
				msgContent.setText(style);
				msgContent.setMovementMethod(LinkMovementMethod.getInstance());


 
 
class NoLineClickSpan extends ClickableSpan implements OnLongClickListener {
		String text;

		public NoLineClickSpan(String text) {
			super();
			this.text = text;
			
		}

		@Override
		public void updateDrawState(TextPaint ds) {
			ds.setColor(ds.linkColor);
			ds.setUnderlineText(false);
		}

		@Override
		public void onClick(View widget) {
				Intent intent = new Intent();
				intent.setClass(context, MoreProblemsActivity.class);
				context.startActivity(intent);
		}
		@Override
		public boolean onLongClick(View v) {
			return false;
		}
	}


 

猜你喜欢

转载自blog.csdn.net/w358637319/article/details/40861157