我是靠谱客的博主 激昂可乐,这篇文章主要介绍同一个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);

最后

以上就是激昂可乐最近收集整理的关于同一个TextView中设置不同颜色与文字大小的全部内容,更多相关同一个TextView中设置不同颜色与文字大小内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部