2013-02-11 23 views
0

假設在我的主應用程序中,我有一個佈局「main_layout.xml」,在我的皮膚(另一個應用程序)應用程序中,我有一個佈局「main_layout2.xml」。如何將另一個應用程序(皮膚)的xml佈局(setContentView())添加到主應用程序?

現在,我怎麼在我的主要的應用程序設置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佈局滲透到主應用程序。

請幫我在這(示例代碼或示例鏈接,這將不勝感激)。

在此先感謝。

回答

0

使用重新佈局與<include/>Click here

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

Muraliganesan:main_layout2存在於其他應用。那麼我如何在我的主應用程序中使用它 – 2013-02-11 14:02:12

相關問題