How to get rid of the underline in a Spannable Str

2019-01-26 02:54发布

I have a Spannable Object with a Clickable Object set to it. When the Spannable String is displayed in the TextView it has blue text and a blue underline (indicating to the user that this Text is Clickable). My problem is how can I prevent appearing the blue underline in TextView?

7条回答
仙女界的扛把子
2楼-- · 2019-01-26 03:33
Try the below code to remove underlined and clicked event on multiple words in textview :



            String str="Angelina Clapped For Lester Kang";
            Spannable span = Spannable.Factory.getInstance().newSpannable(str);

            // 0 to 8 start and  index of Angelina
            span.setSpan(new ClickableSpan(str), 0, 8, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

             //  21 to 32  start and  index of Lester  Kang
            span.setSpan(new ClickableSpan(str), 21, 32, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

            textview.setText(span);

             class ClickableSpan extends ClickableSpan{

                    String clicked;
                    public ClickableSpan (String string) {
                        super();

                    }

                    public void onClick(View v) {
                        Toast.makeText(MyActivity.this,""+((TextView)v).getText().toString(),Toast.LENGTH_SHORT).show();
                    }

                    public void updateDrawState(TextPaint ds) {
                       // override updateDrawState
                        ds.setUnderlineText(false); // set to false to remove underline
                    }
                }
查看更多
登录 后发表回答