zoukankan      html  css  js  c++  java
  • android-修改TextView中部分文字的颜色

     :

     
    textView = (TextView) findViewById(R.id.textview);  
    SpannableStringBuilder builder = new SpannableStringBuilder(textView.getText().toString());  
      
    //ForegroundColorSpan 为文字前景色,BackgroundColorSpan为文字背景色  
    ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.RED);  
    ForegroundColorSpan whiteSpan = new ForegroundColorSpan(Color.WHITE);  
    ForegroundColorSpan blueSpan = new ForegroundColorSpan(Color.BLUE);  
    ForegroundColorSpan greenSpan = new ForegroundColorSpan(Color.GREEN);  
    ForegroundColorSpan yellowSpan = new ForegroundColorSpan(Color.YELLOW);  
      
      
      
    builder.setSpan(redSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);  
    builder.setSpan(whiteSpan, 1, 2, Spannable.SPAN_INCLUSIVE_INCLUSIVE);  
    builder.setSpan(blueSpan, 2, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);  
    builder.setSpan(greenSpan, 3, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);  
    builder.setSpan(yellowSpan, 4,5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);  
      
    textView.setText(builder);  
  • 相关阅读:
    namespace
    kubernetes环境搭建
    verdaccio私有仓库搭建
    mysql中间件proxysql
    MySQL存储引擎
    关于分布式系统
    转载:ETL讲解
    用原生JS 写Web首页轮播图
    javascript——记忆小便签
    转载:JavaScript 的 this 原理
  • 原文地址:https://www.cnblogs.com/niray/p/3931418.html
Copyright © 2011-2022 走看看