Highlight on clickablespan click

后端 未结 7 1486
夕颜
夕颜 2021-01-30 11:18

I\'ve got little problem, i need to remove or customize this orange highlight during clicking on clickablespan. This is my class extending ClickableSpan

public c         


        
7条回答
  •  旧时难觅i
    2021-01-30 11:50

    ClickableSpan linkClick = new ClickableSpan() {
        @Override
        public void onClick(View view) {
            Toast.makeText(getApplicationContext(), "Link Click",
                    Toast.LENGTH_SHORT).show();
            view.invalidate();
        }
    
        @Override
        public void updateDrawState(TextPaint ds) {
            if (textView.isPressed()) {
                ds.setColor(Color.BLUE);
            } else {
                ds.setColor(Color.RED);
            }
            textView.invalidate();
        }
    };
    textView.setHighlightColor(Color.TRANSPARENT);
    
    Spannable spannableString = new SpannableString("Link in TextView");
    spannableString.setSpan(linkClick, 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    textView.setText(spannableString, TextView.BufferType.SPANNABLE);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    

提交回复
热议问题