TextView的用法

来源:互联网 发布:360数据恢复电脑免费版 编辑:程序博客网 时间:2024/06/16 04:06

1、textView设置两种不同颜色字体、大小

TextView textView = new TextView(context);SpannableString styleText = new SpannableString("审批编号:" + bean7006.getData().getUserSchoolFlowOrder().getId());styleText.setSpan(new TextAppearanceSpan(this, R.style.style0), 0, 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);styleText.setSpan(new TextAppearanceSpan(this, R.style.style1), 5, String.valueOf(bean7006.getData().getUserSchoolFlowOrder().getId()).length() + 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);textView.setText(styleText, TextView.BufferType.SPANNABLE);LinearLayout.LayoutParams ll = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);ll.setMargins(0, 10, 0, 0);linearSection.addView(textView, ll);
*引用的R.style.style0和R.style.style1为:

<style name="style0">    <item name="android:textSize">14sp</item>    <item name="android:textColor">@color/textcolorgary</item></style><style name="style1">    <item name="android:textSize">14sp</item>    <item name="android:textColor">@color/textcolor</item></style>


原创粉丝点击