最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 實現(xiàn)不同字體顏色的TextView實現(xiàn)代碼

 更新時間:2017年05月26日 17:23:39   作者:ChuckChenLw  
這篇文章主要介紹了Android 實現(xiàn)不同字體顏色的TextView實現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下

Android 實現(xiàn)不同字體顏色的TextView

遇到的需求,mark一下。

實現(xiàn)代碼:

package com.chuck.recyclerviewdemo;

import android.content.Context;
import android.graphics.Canvas;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.widget.TextView;

import java.util.List;

/**
 * 項目名稱:trunk
 * 類描述:
 * 創(chuàng)建人:Administrator
 * 創(chuàng)建時間:2015/12/10 14:05
 * 修改人:Administrator
 * 修改時間:2015/12/10 14:05
 * 修改備注:
 */
public class DifferentColorTextView extends TextView{
 public DifferentColorTextView(Context context) {
  super(context);
 }

 public DifferentColorTextView(Context context, AttributeSet attrs) {
  super(context, attrs);
 }

 public DifferentColorTextView(Context context, AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);
 }

 @Override
 protected void onDraw(Canvas canvas) {
  super.onDraw(canvas);
 }
 public void setDifferentColorText(List<String> text,List<Integer>colors){
  setText(calculateResidue(text,colors));
 }
 /**顯示不同顏色*/
 private SpannableStringBuilder calculateResidue(List<String> text, List<Integer>colors) {
  if(text==null||colors==null){
   return null;
  }
  StringBuilder sb =new StringBuilder();
  for (int i=0;i<text.size();i++){
   sb.append(text.get(i));
  }
  SpannableStringBuilder ssb=new SpannableStringBuilder(sb.toString());
  int begin=0;
  for (int i=0;i<text.size();i++){
   ForegroundColorSpan mSpan = new ForegroundColorSpan(colors.get(i));
   ssb.setSpan(mSpan,begin,begin+text.get(i).length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
   begin=begin+text.get(i).length();
  }
  return ssb;
 }
}

   實現(xiàn)同一textView,不同顏色。

        感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論

兴和县| 名山县| 福海县| 武川县| 咸阳市| 郑州市| 澄江县| 滕州市| 涿鹿县| 福州市| 高雄市| 景德镇市| 玛多县| 凤翔县| 湖州市| 鹰潭市| 县级市| 黄石市| 渭南市| 镇远县| 普格县| 腾冲县| 洛隆县| 和硕县| 徐州市| 张家口市| 石家庄市| 武邑县| 江达县| 临沭县| 延吉市| 柯坪县| 当雄县| 平江县| 阿鲁科尔沁旗| 德格县| 新余市| 天祝| 栾城县| 宜良县| 娄烦县|