真是x了狗瓢棒,本來(lái)一個(gè)很簡(jiǎn)單的問(wèn)題浴韭,搞了一下午,確認(rèn)好幾遍沒(méi)發(fā)現(xiàn)代碼有什么問(wèn)題脯宿,索性不搞了念颈,下班回家!吃完飯還是沒(méi)忍住连霉,強(qiáng)迫癥嘛榴芳,打開(kāi)電腦再詳細(xì)觀察下代碼,尼瑪呀跺撼,問(wèn)題出來(lái)了窟感!
先說(shuō)下正確使用方法吧:
用法很簡(jiǎn)單的如下:
ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.parseColor("#06b6f2"));
int index = question.indexOf(mKeyWord);
int len = mKeyWord.length();
SpannableString spannableString = new SpannableString(question);
spannableString.setSpan(colorSpan, index, index + len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
holder.nameTv.setText(spannableString);
一時(shí)腦殘的我竟然寫(xiě)成了這樣:
ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.parseColor("#06b6f2"));
int index = question.indexOf(mKeyWord);
int len = mKeyWord.length();
SpannableString spannableString = new SpannableString(question);
spannableString.setSpan(colorSpan, index, index + len, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
holder.nameTv.setText(faqBean.getId() + "、"+spannableString);//這段代碼要哭了