除TextView超链接下划线

     没发现有相关的属性,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);
	    }
    } 

猜你喜欢

转载自obacow.iteye.com/blog/1989009