---
title: "除TextView超链接下划线"
author: "hemowolf"
date: "2013-12-13T10:11:11Z"
tags: []
categories: ["移动开发"]
slug: "textview"
draft: false
lastmod: "2013-12-13T10:11:29Z"
id: 1989009
url: "https://obacow.iteye.com/blog/1989009"
---

没发现有相关的属性，google一下都是重写Span。做个记录

```
    private void stripUnderLines(TextView tv) {
	try {
	    Spannable text = (Spannable) tv.getText();
	    if (text == null)
		return;
	    URLSpan[] old = text.getSpans(0, text.length(), URLSpan.class);
	    if (old == null)
		return;

	    for (int i = old.length - 1; i >= 0; i--) {
		URLSpan us = old[i];
		final int start = text.getSpanStart(us), end = text.getSpanEnd(us), flags = text.getSpanFlags(us);
		text.removeSpan(us);
		text.setSpan(new MyURLSpan(us.getURL()), start, end, flags);
	    }
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }
    
    private final class MyURLSpan extends URLSpan{
	    public MyURLSpan(String url) {
	        super(url);
	    }
	    public MyURLSpan(Parcel src) {
		super(src);
	    }
	    
	    public void updateDrawState(TextPaint ds) {
		ds.setColor(ds.linkColor);
	        ds.setUnderlineText(false);
	    }
    } 
```