在TextView

时间:2017-01-18 02:06:14

标签: android onclick textview focus motionevent

我正在使用自定义的LinkMovementMethod课程来自定义我的文字onClick,该文字效果非常好,但是当它单击Clickable字时它仍然按下显示

enter image description here

我怎么能释放它

这里也是我使用的自定义类

public abstract class TextViewLinkHandler extends LinkMovementMethod {

private String text;

public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    if (event.getAction() != MotionEvent.ACTION_UP)
        return super.onTouchEvent(widget, buffer, event);

    int x = (int) event.getX();
    int y = (int) event.getY();

    x -= widget.getTotalPaddingLeft();
    y -= widget.getTotalPaddingTop();

    x += widget.getScrollX();
    y += widget.getScrollY();

    Layout layout = widget.getLayout();
    int line = layout.getLineForVertical(y);
    int off = layout.getOffsetForHorizontal(line, x);

    URLSpan[] link = buffer.getSpans(off, off, URLSpan.class);

    CharSequence charSequence = widget.getText();
    if (charSequence instanceof Spannable) {
        Spannable spannableText = (Spannable)charSequence;
        ClickableSpan[] spans = spannableText.getSpans(0, widget.length(), ClickableSpan.class);
        for (ClickableSpan span55555 : spans) {
            int start55555 = spannableText.getSpanStart(span55555);
            int end55555 = spannableText.getSpanEnd(span55555);
            Log.i("tessst", String.valueOf(charSequence.subSequence(start55555, end55555)));
            text = String.valueOf(charSequence.subSequence(start55555, end55555));
        }
    }

    if (link.length != 0) {
        onLinkClick(link[0].getURL(),TextViewLinkHandler.this.text);
        widget.invalidate();
    }
    return true;
}

abstract public void onLinkClick(String url,String text);
}

0 个答案:

没有答案