同一个TextView中设置不同颜色与文字大小

{
final SpannableStringBuilder sb = new SpannableStringBuilder(“your text here”);
final ForegroundColorSpan fcs = new ForegroundColorSpan(Color.rgb(158, 158, 158)); // Span to set text color to some RGB value
final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD); // Span to make text bold
sb.setSpan(fcs, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE); // Set the text color for first 4 characters
sb.setSpan(bss, 0, 4, Spannable.SPAN_INCLUSIVE_INCLUSIVE); // make them also bold
yourTextView.setText(sb);
}

String resultTxt = text + unitStr;
Spannable spanResult = new SpannableString(resultTxt);
int txtLength = text.length();
spanResult.setSpan(new AbsoluteSizeSpan(HKFontResources.getDimensionInt8()), 0,
txtLength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spanResult.setSpan(new AbsoluteSizeSpan(HKFontResources.getDimensionUnit()), txtLength,
resultTxt.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(spanResult);

Spannable WordtoSpan = new SpannableString(“大字小字”);
WordtoSpan.setSpan(new AbsoluteSizeSpan(20), 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
WordtoSpan.setSpan(new AbsoluteSizeSpan(14), 2, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
remoteViews.setCharSequence(R.id.text11, “setText”, WordtoSpan);
ComponentName com = new ComponentName(“com.jftt.widget”, “com.jftt.widget.MyWidgetProvider”);
appWidgetManager.updateAppWidget(com, remoteViews);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值