假设在我的主应用程序中我有一个布局“main_layout.xml”并且在我的皮肤(另一个应用程序)应用程序中我有一个布局“main_layout2.xml”。
现在,如果安装了皮肤应用程序,如果未安装setContentView(main_layout2)
setContentView(R.layout.main_layout);
我非常了解:
[In Theme package]
1. set action for activity, for example: my.package.theme
2. add all files you need for this theme
[In main app]
// Create intent with your action: my.package.theme
Intent intent = new Intent();
intent.setAction("my.package.theme");
// Get list of all installed packages with your themes
List<ResolveInfo> lresolve = pm.queryIntentActivities(intent, 0);
int size = lresolve.size();
for (int i = 0; i < size; i++) {
ApplicationInfo appInfo = lresolve.get
(i).activityInfo.applicationInfo;
try {
Resources resSkin = pm.getResourcesForApplication(appInfo);
int backres = resSkin.getIdentifier("my_background", "drawable",
appInfo.packageName);
// getting background from theme package
Drawable background = resSkin.getDrawable(backres);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
通过上面的代码我可以改变图像。但是如何将其他应用程序的xml布局渗透到主应用程序。
请帮助我(示例代码或示例链接,我们将不胜感激)。
提前致谢。