Ash Ash - 1 year ago 67
Android Question

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

Currently 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 the blue underline from not coming up? I have searched around but cannot find anything.

Answer Source

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) {
        clicked = string;

    public void onClick(View tv) {
       Toast.makeText(MainActivity.this,clicked , Toast.LENGTH_SHORT).show();

    public void updateDrawState(TextPaint ds) {// override updateDrawState
        ds.setUnderlineText(false); // set to false to remove underline
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download