小编Sid*_*aik的帖子

从另一个 apk 动态加载资源(布局)

我设法拉出布局,并将其添加到我的 viewflipper 中,但是,它在那里加载为空白。

代码是,

Resources packageResources;
Context packageContext;
try
{   
    packageResources = pm.getResourcesForApplication(packageName);
    packageContext = this.createPackageContext(packageName,     Context.CONTEXT_INCLUDE_CODE + Context.CONTEXT_IGNORE_SECURITY);                
 }
 catch(NameNotFoundException excep)
 {
     // the package does not exist. move on to see if another exists.
 }

 Class layoutClass;
 try
 {
       // using reflection to get the layout class inside the R class of the package
       layoutClass = packageContext.getClassLoader().loadClass(packageName + ".R$layout");
 }
 catch (ClassNotFoundException excep1)
 {
     // Less chances that class won't be there.
 }

 for( Field layoutID : layoutClass.getFields() …
Run Code Online (Sandbox Code Playgroud)

resources layout android dynamic

5
推荐指数
1
解决办法
3727
查看次数

标签 统计

android ×1

dynamic ×1

layout ×1

resources ×1