我在内部有textview,我想在文本中间更改文本的文本大小,如下所示
答案 0 :(得分:3)
String text1 = "Hi";
String text2 = "there";
SpannableString span1 = new SpannableString(text1);
span1.setSpan(new AbsoluteSizeSpan(textSize1), 0, text1.length(), SPAN_INCLUSIVE_INCLUSIVE);
SpannableString span2 = new SpannableString(text2);
span2.setSpan(new AbsoluteSizeSpan(textSize2), 0, text2.length(), SPAN_INCLUSIVE_INCLUSIVE);
// let's put both spans together with a separator and all
CharSequence finalText = TextUtils.concat(span1, " ", span2);
答案 1 :(得分:2)
//使用Html.fromHtml(str)
String str="<font size =\"20\"><B>Bold</B> <br/> Then Normal Text<br/>
<i>Then Italic</i> </font>" +
"<br/> <font color=\"green\" >this is simple sentence </font>" +
"<br/> <font face=\"verdana\" >this is simple sentence </font>"+
"<br/><br/><br/><br/><a>this is simple sentence</a>";
Spanned strHtml= Html.fromHtml(str);
TextView tv = (TextView)findViewById(R.id.textView);
tv.setText(strHtml);
或者您可以使用