android jar包方式获取资源
2015-08-16 15:59
543 查看
本文从其他博客摘录,我们常碰到将程式打包成jar方式发给别人调用,但在获取资源时用普的R.id方式会导致报异常(找不到)
public class Helper
{
public static int getLayoutId(Context context ,String name)
{
return context.getResources().getIdentifier(name, "layout", context.getPackageName());
}
public static int getResId(Context context ,String name)
{
return context.getResources().getIdentifier(name,"id",context.getPackageName());
}
public static int getResDraw(Context context ,String name)
{
return context.getResources().getIdentifier(name,"drawable",context.getPackageName());
}
public static int getResStyle(Context context ,String name)
{
return context.getResources().getIdentifier(name,"style",context.getPackageName());
}
public static int getResStr(Context context ,String name)
{
return context.getResources().getIdentifier(name,"string",context.getPackageName());
}
public static int getResXml(Context context ,String name)
{
return context.getResources().getIdentifier(name,"xml",context.getPackageName());
}
}
public class Helper
{
public static int getLayoutId(Context context ,String name)
{
return context.getResources().getIdentifier(name, "layout", context.getPackageName());
}
public static int getResId(Context context ,String name)
{
return context.getResources().getIdentifier(name,"id",context.getPackageName());
}
public static int getResDraw(Context context ,String name)
{
return context.getResources().getIdentifier(name,"drawable",context.getPackageName());
}
public static int getResStyle(Context context ,String name)
{
return context.getResources().getIdentifier(name,"style",context.getPackageName());
}
public static int getResStr(Context context ,String name)
{
return context.getResources().getIdentifier(name,"string",context.getPackageName());
}
public static int getResXml(Context context ,String name)
{
return context.getResources().getIdentifier(name,"xml",context.getPackageName());
}
}
相关文章推荐
- 自学成才的秘密:115个 web Develop 资源
- C#中使用资源的方法分析
- Shell脚本实现Linux系统和进程资源监控
- Android 中动态加载.jar的实现步骤
- Android资源命名规范 分享
- java使用命令行打包JAR
- 用代码更新你的jar包
- 用Java连接sqlserver数据库时候几个jar包的区别分析
- .net非托管资源的回收方法
- 基于将Android工程做成jar包和资源文件的解决方法
- jar包双击执行程序的方法
- 从Java的jar文件中读取数据的方法
- Jar打包用法详解
- 基于Java的打包jar、war、ear包的作用与区别详解
- dom4j从jar包中读取xml文件的方法
- java生成jar包的方法
- jar命令的用法详解
- Smarty使用自定义资源的方法
- python实现计算资源图标crc值的方法
- 将Python代码打包为jar软件的简单方法