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));  
  • 相关阅读:
    Winsock 2 入门指南
    Winsock 2 入门指南
    [手游新项目历程]-40-linux环境实现C/C++程序崩溃退出时打印栈信息
    1月下旬解题
    poj1226,poj3080
    poj3666
    poj3067
    poj12月其他题解(未完)
    poj1823,3667
    poj2352
  • 原文地址:https://www.cnblogs.com/Free-Thinker/p/9081123.html
Copyright © 2011-2022 走看看