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

后端 未结 10 2017
陌清茗
陌清茗 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:13

    simplest way is

     string1 = new SpannableString("By Tapping Register You Agree To The \nTerms And Conditions");
        ClickableSpan clickableSpan = new ClickableSpan() {
            @Override
            public void onClick(View widget) {
                Toast.makeText(getApplicationContext(),"clicked",Toast.LENGTH_SHORT).show();
            }
            @Override
            public void updateDrawState(TextPaint ds) {
            ds.setUnderlineText(false);    // this line removes underline
            }
    
        };
        text_terms.setMovementMethod(LinkMovementMethod.getInstance());
        string1.setSpan(clickableSpan,37,string1.length(),0);
        text_terms.setText(string1);
    

提交回复
热议问题