【问题标题】:How to add xml layout(setContentView()) of another app(skin) to main app?如何将另一个应用程序(皮肤)的 xml 布局(setContentView())添加到主应用程序?
【发布时间】:2013-01-26 12:29:44
【问题描述】:

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

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

提前致谢。

【问题讨论】:

    标签: android themes skins


    【解决方案1】:

    通过 &lt;include/&gt; Click here 重复使用布局

     <include layout="@layout/main_layout2"/>
    

    【讨论】:

    • Muraliganesan:main_layout2 存在于另一个应用程序中。那么我如何在我的主应用程序中使用它
    猜你喜欢
    • 2011-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-03
    • 1970-01-01
    • 2013-02-12
    • 1970-01-01
    • 2012-02-13
    相关资源
    最近更新 更多