简体   繁体   中英

Android: Clickable span selects the text in textview

So Im using this Clickable span as well as Underline Span to make the parts of my text clickable, but whenever I touch any of those "clickable" parts of the text, the listener does gets called but it selects the text as well. Just like a selector, Now even if this is a default feature with clickable spans, it should disappear on its own but rather I have to touch randomly on the screen to make it disappear. Can anyone please set me to the right track here? thanks 在此处输入图片说明

spannableString.setSpan(underlineSpan1,60,text.length()-1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        ClickableSpan clickableSpan=new ClickableSpan() {
            @Override
            public void onClick(View view) {
                Toast.makeText(LoginScreen.this,"Dummy text",Toast.LENGTH_SHORT).show();
             }
        };
        spannableString.setSpan(clickableSpan,39,55, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        tvTerms.setText(spannableString);
        tvTerms.setMovementMethod(LinkMovementMethod.getInstance());

Solution:

Add this line at the end:

textView.setHighlightColor(Color.TRANSPARENT);

May be this will help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM