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

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

    Use the below code and try

    String mystring =" Hello";
    SpannableString ss= new SpannableString(mystring);
    ss.setSpan(new MyClickableSpan(mystring), 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);  
    
    class MyClickableSpan extends ClickableSpan{// extend ClickableSpan     
    
        String clicked;
        public MyClickableSpan(String string) {
            super();
            clicked = string;
        }
        @Override
        public void onClick(View tv) {
           Toast.makeText(MainActivity.this,clicked , Toast.LENGTH_SHORT).show();
        }
    
        @Override
        public void updateDrawState(TextPaint ds) {// override updateDrawState
            ds.setUnderlineText(false); // set to false to remove underline
        }
    }
    

提交回复
热议问题