是否可以在同一文本视图中更改字符串的字体大小和颜色。
例如:
_______________
|_______________| --> this is my text view
我想做什么
________________
|ABC (red color) |
|abc(whitecolor) |
|________________|
字符串应该如下所示" ABC \ nabc"
答案 0 :(得分:0)
使用SpannableStringBuilder
SpannableStringBuilder builder = new SpannableStringBuilder();
SpannableString str1= new SpannableString("Text1");
str1.setSpan(new ForegroundColorSpan(Color.RED), 0, str1.length(), 0);
builder.append(str1);
SpannableString str2= new SpannableString(appMode.toString());
str2.setSpan(new ForegroundColorSpan(Color.WHITE), 0, str2.length(), 0);
builder.append(str2);
TextView tv = (TextView) view.findViewById(android.R.id.text1);
tv.setText( builder, TextView.BufferType.SPANNABLE);