zoukankan      html  css  js  c++  java
  • android 一个TextView设置多种颜色

    时候一个文本框为了强调内容需要显示不同颜色,用以下代码可以轻松实现

    方法一:(适用于颜色变化多的情况)

    //为文本框设置多种颜色  
    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));  
  • 相关阅读:
    【jQuery】添加删除记录练习
    git
    常用正则表达式
    【资源】前端插件
    menu 菜单显示隐藏-jquery实现
    java作业——Day006
    java作业——Day005
    java作业——Day004
    java作业——Day003
    java作业——Day001
  • 原文地址:https://www.cnblogs.com/wei1228565493/p/4903771.html
Copyright © 2011-2022 走看看