谢谢Shai和tizbn,我仔细考虑了你的两个答案。之后,我创建了以下方法来完成我的要求,也许对其他人有用。
/**
* Increases or reduces of a given percentage all the font sizes of a given
* theme, overlaying a new theme containing only the new font sizes. The
* font sizes will be increased when the percentage is positive, they will
* be reduced when the percentage is negative. Legal percentage values are
* from -90 to 300.
*
* Example of usage: changeFontSizesOfTheme(theme, "Theme", 50);
*
* @param theme the given resource file
* @param themeName the name of given theme
* @param percentage the given percentage to increase or reduce the font
* sizes
*/
public static void changeFontSizesOfTheme(Resources theme, String themeName, int percentage) {
if (theme.isTheme(themeName) && percentage != 0 && percentage >= -90 && percentage <= 300) {
Hashtable hashtable = theme.getTheme("Theme");
Hashtable overlay = new Hashtable();
Set<String> keys = hashtable.keySet();
Iterator<String> itr = keys.iterator();
String key;
Object value;
int count = 0;
while (itr.hasNext()) {
key = itr.next();
value = hashtable.get(key);
if (value instanceof Font) {
Font originalFont = (Font) value;
float originalFontSize = originalFont.getPixelSize();
float newFontSize = originalFontSize * (100 + percentage) / 100;
overlay.put(key, originalFont.derive(newFontSize, originalFont.getStyle()));
count++;
}
}
UIManager.getInstance().addThemeProps(overlay);
Log.p(count + " font sizes of the theme \"" + themeName + "\" were overlayed");
}
}