• 在TextView使用部分颜色文字


    /**
    	 * change a part of string color.
    	 * 
    	 * @param string
    	 *            whole string.
    	 * @param subString
    	 *            the sub string need modify color.
    	 * @param color
    	 *            the the color you want the sub string display. can get like
    	 *            {@link Context#getResources()}.getColor(R.color.xxx) or use
    	 *            the system {@link Color}.xxx;
    	 * @return a spannableStringBuilder(a string after modify substring color).
    	 */
    	public static SpannableStringBuilder modifyStrColor(String string, String subString, int color) {
    		String tipRed = String.format(string, subString);
    		int index[] = new int[1];
    		index[0] = tipRed.indexOf(subString);
    		SpannableStringBuilder style = new SpannableStringBuilder(tipRed);
    		style.setSpan(new ForegroundColorSpan(color), index[0],
    				index[0] + subString.length(),
    				Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
    		return style;
    	}

               直接使用TextView.setText该方法的返回值即可。

  • 相关阅读:
    org.apache.jasper.JasperException
    泛型接口
    Mysql学习
    深入分析ClassLoader
    空格哥的第一篇Blog
    [Maven] Missing artifact
    sftp新建用户步骤
    遍历map的6种方式
    利用aop插入异常日志的2种方式
    Mybatis-Oralce批量插入方法
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3293813.html
Copyright © 2020-2023  润新知