本文介绍了如何摆脱带有Clickable对象的Spannable字符串中的下划线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个设置为Clickable ObjectSpannable Object.当Spannable String显示在TextView中时,它具有蓝色文本和蓝色下划线(向用户指示此文本是可单击的).我的问题是如何防止在TextView中出现蓝色下划线?

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?

推荐答案

使用以下代码并尝试

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
    }
}

这篇关于如何摆脱带有Clickable对象的Spannable字符串中的下划线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 11:43