通过包名读取资源文件

public static   int getElementID(String name,String resType){
Resources mainPackageRes = Context.getResources();
int id = 0;
//从主包 中找资源
if("id".equals(resType)||"layout".equals(resType)||"string".equals(resType)||"style".equals(resType)){
id = mainPackageRes.getIdentifier(name, resType, SkinManagerObservable.getInstance().getmContext().getPackageName());
}else /*("drawable".equals(resType) || "color".equals(resType) || "string".equals(resType))*/{
 id = mainPackageRes.getIdentifier(name, resType, Context.getPackageName()); 
}
return id;

}



你可能感兴趣的:(android小技巧)