一个textview表示价格的时候,¥符号要小一些,好吧,就按照下面这代码搞就行了。
String text = new String("¥" + "2000");
Log.i("cdscvdscdscsd", text);
SpannableString spannableString = new SpannableString(text);
int size = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 11, getResources()
.getDisplayMetrics());
spannableString.setSpan(new AbsoluteSizeSpan(size), 0, 1, Spanned
.SPAN_EXCLUSIVE_EXCLUSIVE);//设置字体大小
spannableString.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.green)), 0, 1,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);//设置字体颜色
int size2 = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16, getResources
().getDisplayMetrics());
spannableString.setSpan(new AbsoluteSizeSpan(size2), text.length() - 1, text.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);//设置字体大小
spannableString.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.green)), text.length
() - 1, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);//设置字体颜色
tv_title_name.setText(spannableString);
一个textview字体大小一样,但是里面个别字颜色不一样,且这些字是动态获取。
String str1 = "<font color='#f68113'>" + RandomUtil.getNum() + "</font>";
String str2 = "<font color='#f68113'>" + RandomUtil.getNum() + "</font>";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fresh_sucess);
textView = (TextView) findViewById(R.id.tv_fresh_info);
textView.setText(Html.fromHtml("您的简历优鲜度提升了" + str1 + "%,<br/>排序更新提前了" + str2 + "位!<br/>您的简历将会精准推送到更多企业!"));
}