Android TextView 部分字符高亮


Android TextView 部分字符高亮

方法一 :

String str="imp"; 
textView.setText(Html.fromHtml("<font color=\"#ff0000\">"+str));

方法二 :

SpannableStringBuilder styled = new SpannableStringBuilder(textView.getText());

// i 未起始字符索引,j 為結束字符索引
styled.setSpan(new ForegroundColorSpan(Color.RED), i, j,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

textView.setText(styled);

方法三 :

textView.setText(Html.fromHtml("<font color=\"#ff0000\">紅色</font>其它顏色"));

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM