TextView内容多颜色

2017-01-22  本文已影响0人  Dennis川

public static String secToStrTime(int time,String des ) {

    String timeStr = null;
    int hour = 0;
    int minute = 0;
    int second = 0;
    if (time <= 0) {
        return format(0, 0, 0, des);
    }  else {
        int day = time / (60 * 60 * 24);
        int i1 = time % (60 * 60 * 24);
        hour = i1 / (60 * 60);
        int i2 = i1 % (60 * 60);
        minute = i2 / 60;
        return format( day, hour, minute, des);
    }

}
public static String format(int day, int hour, int minute, String des){
    if (des.equals("")) {
        return String.format("<font color=\"#f88400\">%s</font><font color=\"#a1a1a1\">天</font><font color=\"#f88400\">%s</font><font color=\"#a1a1a1\">时</font><font color=\"#f88400\">%s</font><font color=\"#a1a1a1\">分</font>", day, hour, minute);
    }
       else {
        return String.format("<font color=\"#a1a1a1\">%s</font><font color=\"#f88400\">%s</font><font color=\"#a1a1a1\">天</font><font color=\"#f88400\">%s</font><font color=\"#a1a1a1\">时</font><font color=\"#f88400\">%s</font><font color=\"#a1a1a1\">分</font>",des, day, hour, minute);

    }
}

注意:</font>写全。
调用:
String str1 = TimeUtils.secToStrTime(tBean.getExpireTime(), "");
holder.tvTimeTitle.setText(Html.fromHtml(str1));

显示结果:

Paste_Image.png
上一篇下一篇

猜你喜欢

热点阅读