0

假设在我的主应用程序中我有一个布局“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 布局渗透到主应用程序。

请帮助我(示例代码或示例链接,将不胜感激)。

提前致谢。

4

1 回答 1

0

单击此处重用布局<include/>

 <include layout="@layout/main_layout2"/>
于 2013-02-11T12:12:00.800 回答