一个文本框2种字体大小、颜色

来源:互联网 发布:mac 安装node sass 编辑:程序博客网 时间:2024/06/05 15:58

第一种方法:

        //设置两种字体大小        Spannable WordtoSpan = new SpannableString(codeMemoTV.getText().toString());        WordtoSpan.setSpan(new AbsoluteSizeSpan((int) DimensionUtil.convertDpToPixel(18, this)), 0, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);        codeMemoTV.setText(WordtoSpan);        //设置两种字体颜色和大小        Spannable WordtoSpan1 = new SpannableString("好友成交额6255.50元");        WordtoSpan1.setSpan(new AbsoluteSizeSpan((int) DimensionUtil.convertDpToPixel(18, this)), 5, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);        WordtoSpan1.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.black)), 5, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);        codeMemoTV.setText(WordtoSpan1);

或者:

msgTV.setText(Html.fromHtml(String.format("%s出价 <font color=\"#f06c55\">%.0f</font>元", item.getIsPerPrice() , item.getBidPrice())));

效果图:


0 2