反射另一个app中的View

FrameLayout fl = (FrameLayout) findViewById(R.id.content);
View v = null;
try {
  Context context = createPackageContext("com.sohu.news", Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY); 
  int id = context.getResources().getIdentifier("activity_main", "layout","com.sohu.news"); 
  v = LayoutInflater.from(context).inflate(id, null); 
  v.setTag(this); 
} catch (NameNotFoundException e) { 
  e.printStackTrace(); 
} 
if (v != null) { 
  fl.addView(v); 
}

  

posted @ 2017-02-06 16:46  DemonCoder  阅读(506)  评论(0编辑  收藏  举报