下面列出了android.content.res.Resources.Theme#applyStyle() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private Theme getPreloaderTheme() {
Object tag = getTag();
int style = ((tag != null) && (tag instanceof ShortcutInfo) &&
(((ShortcutInfo) tag).container >= 0)) ? R.style.PreloadIcon_Folder
: R.style.PreloadIcon;
Theme theme = sPreloaderThemes.get(style);
if (theme == null) {
theme = getResources().newTheme();
theme.applyStyle(style, true);
sPreloaderThemes.put(style, theme);
}
return theme;
}
private Theme getPreloaderTheme() {
Object tag = getTag();
int style = ((tag != null) && (tag instanceof ShortcutInfo) &&
(((ShortcutInfo) tag).container >= 0)) ? R.style.PreloadIcon_Folder
: R.style.PreloadIcon;
Theme theme = sPreloaderThemes.get(style);
if (theme == null) {
theme = getResources().newTheme();
theme.applyStyle(style, true);
sPreloaderThemes.put(style, theme);
}
return theme;
}
@Override
protected void onApplyThemeResource(Theme theme, int resid, boolean first) {
theme.applyStyle(resid, true);
}
private void fillPluginTheme(ActivityPlugin plugin) {
Theme pluginTheme = plugin.from().pluginRes.newTheme();
pluginTheme.setTo(super.getTheme());
plugin.setTheme(pluginTheme);
PackageInfo packageInfo = plugin.from().pluginPkgInfo;
String mClass = plugin.getTopActivityName();
Log.i(TAG, "Before fill Plugin 's Theme,We check the plugin:info = "
+ packageInfo + "topActivityName = " + mClass);
int defaultTheme = packageInfo.applicationInfo.theme;
ActivityInfo curActivityInfo = null;
for (ActivityInfo a : packageInfo.activities) {
if (a.name.equals(mClass)) {
curActivityInfo = a;
if (a.theme != 0) {
defaultTheme = a.theme;
} else if (defaultTheme != 0) {
// ignore
} else {
// 支持不同系统的默认Theme
if (Build.VERSION.SDK_INT >= 14) {
defaultTheme = android.R.style.Theme_DeviceDefault;
} else {
defaultTheme = android.R.style.Theme;
}
}
break;
}
}
pluginTheme.applyStyle(defaultTheme, true);
setTheme(defaultTheme);
if (curActivityInfo != null) {
getWindow().setSoftInputMode(curActivityInfo.softInputMode);
}
if (CJConfig.usePluginTitle) {
CharSequence title = null;
try {
title = CJTool.getAppName(this, plugin.getPluginPath());
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (title != null)
setTitle(title);
}
}