概述
{
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中设置不同颜色与文字大小所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复