How to get rid of the underline in a Spannable String with a Clickable Object?

后端 未结 10 2019
陌清茗
陌清茗 2021-02-03 16:44

I have a Spannable Object with a Clickable Object set to it. When the Spannable String is displayed in the TextView it has bl

10条回答
  •  余生分开走
    2021-02-03 17:12

    This works for me. No need to create custom ClickableSpan class. Just override updateDrawState(TextPaint ds).

    SpannableString span = new SpannableString("Some text");
    ClickableSpan clickSpan = new ClickableSpan() {
        @Override
        public void updateDrawState(TextPaint ds) {
            ds.setColor(ds.linkColor);    // you can use custom color
            ds.setUnderlineText(false);    // this remove the underline
        }
    
        @Override
        public void onClick(View textView) {
            // handle click event
        }
    };
    
    span.setSpan(clickSpan, 5, span.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    yourTextView.setText(span);
    

提交回复
热议问题