方法一
public static void increaseFontSizeForPath(Spannable spannable, String path, float increaseTime) {
int startIndexOfPath = spannable.toString().indexOf(path);
spannable.setSpan(new RelativeSizeSpan(increaseTime), startIndexOfPath,
startIndexOfPath + path.length(), 0);
}
使用
Utils.increaseFontSizeForPath(spannable, "big", 3); // make "big" text bigger 3 time than normal text

方法2
public static void setFontSizeForPath(Spannable spannable, String path, int fontSizeInPixel) {
int startIndexOfPath = spannable.toString().indexOf(path);
spannable.setSpan(new AbsoluteSizeSpan(fontSizeInPixel), startIndexOfPath,
startIndexOfPath + path.length(), 0);
}
使用
Utils.setFontSizeForPath(spannable, "big", (int) textView.getTextSize() + 20); // make "big" text bigger 20px than normal text
