設置一個TextView書名標紅且數(shù)字字號變大

設置一個TextView中書名標紅且數(shù)字字號變大

String str = “經(jīng)過分析,以下內(nèi)容很適合您的寶貝學習:《蝦醫(yī)生》、《做一個自律的孩子》、《為什么泰國被稱為“大象之邦”》建議引導寶貝學習喲!”;

tv.setText(setNumColorAndBook(str));

public static SpannableStringBuilder setNumColorAndBook(Stringstr) {

SpannableStringBuilder style=new SpannableStringBuilder(str);

for(inti=0;i<str.length();i++) {

chara=str.charAt(i);

if(a>='0' && a<='9') {

style.setSpan(new ForegroundColorSpan(Color.parseColor("#FF7862")),i,i+1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

style.setSpan(new StyleSpan(Typeface.BOLD),i,i+1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

style.setSpan(new RelativeSizeSpan(1.15f),i,i+1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

? ? ? ? ?? }

? ? ?? }

?

if(str.contains("《") && str.contains("》")) {

str=str.replace("、","\n");

int begin=str.indexOf("《");

StringBuilder stringBuilder=new StringBuilder(str);

StringBuilder reverse=stringBuilder.reverse();

int indexOf1=reverse.indexOf("》");

int length=str.length();

int last=length-indexOf1;

Log.e("http-顏色位置:",length+"**"+begin+"**"+last);

// ? ? ?? SpannableString spannableString = new SpannableString(str);

style.setSpan(new ForegroundColorSpan(Color.parseColor("#FF7862")),begin,last,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

style.setSpan(newStyleSpan(Typeface.BOLD),begin,last,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

? ? ?? }

returnstyle;

?? }

效果如下:


?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容