使用动态范围设置样式文本不起作用

时间:2016-06-22 09:43:56

标签: java android

我想动态更改textize和字符串的样式:

private Spannable styleSpan(String string, int style) {
    Spannable sb = new SpannableString( string );
    sb.setSpan(new StyleSpan(style), 0, string.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE );
    return sb;
}

private Spannable changeSize(String string, int size) {
    Spannable sb = new SpannableString( string );
    sb.setSpan(new AbsoluteSizeSpan(size), 0, string.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE );
    return sb;
}

现在我有了这个字符串:

date = TextUtils.concat(styleSpan(startDay, android.graphics.Typeface.BOLD)+"."+startMonth+" "+
        changeSize(startHour, 40)+":"+changeSize(startMinute, 40)+" → "+changeSize(endHour, 50)+
        ":"+changeSize(endMinute, 50)).toString();
dateTime.setText(date); // is a TextView

但由于某种原因,文本根本没有样式。

0 个答案:

没有答案