Android一个TextView设置多种颜色的2种高效方法
2014-12-23 23:36
519 查看
有时候一个文本框为了强调内容需要显示不同颜色,用以下代码可以轻松实现
方法一:(适用于颜色变化多的情况)
方法二:(高校,快捷)
首先在字符串中就设置好颜色属性
然后用Html.fromHtml()方法
像这种情况用一个文本框来实现会很省事
方法一:(适用于颜色变化多的情况)
//为文本框设置多种颜色 textView=(TextView)findViewById(R.id.text_show); SpannableStringBuilder style = new SpannableStringBuilder("备注:签收人(张三)"); style.setSpan(new ForegroundColorSpan(Color.BLUE), 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); style.setSpan(new ForegroundColorSpan(Color.RED), 7, 9, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(style);
方法二:(高校,快捷)
首先在字符串中就设置好颜色属性
String str1=String.format("价格 :<font color=\"#d40000\">%s", String.format("¥%1$.2f元", item.getPrice())); String str2=String.format("状态 :<font color=\"#666666\">%s", "已售");
然后用Html.fromHtml()方法
mStaringPriceTV.setText(Html.fromHtml(str1)); mCountdownTimeTV.setText(Html.fromHtml(str2));
像这种情况用一个文本框来实现会很省事
相关文章推荐
- Android一个TextView设置多种颜色的2种高效方法
- android 一个TextView设置多种颜色
- android TextView的字体颜色设置的多种方法
- android TextView的字体颜色设置的多种方法(转)
- android TextView的字体颜色设置的多种方法
- Android 一个TextView中设置文字不同字体大小和颜色的最完整方法
- Android TextView设置值时,使一个字符串有不同颜色(多种颜色)
- Android设置TextView字体呈现多种颜色的方法
- android TextView的字体颜色设置的多种方法(续)
- android TextView的字体颜色设置的多种方法
- android TextView的字体颜色设置的多种方法
- 【Android基础】TextView的字体颜色设置的多种方法
- 一个textview里设置多种字体颜色,并添加图片
- android 一个 textview 设置不同的字体大小和颜色
- Android TextView字体颜色设置方法小结
- TextView 文字颜色设置的多种方法
- android 一个 textview 设置不同的字体大小和颜色
- Android中TextView多种颜色的设置
- android 一个 textview 设置不同的字体大小和颜色
- android TextView设置颜色方法