設置一個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;
?? }
效果如下:
