使用getIdentifier()方法可以方便的获各应用包下的指定资源ID。
2013-11-18 13:45
489 查看
使用getIdentifier()方法可以方便的获各应用包下的指定资源ID。
主要有两种方法:
(1)方式一
Resources resources = context.getResources();
int indentify = resources.getIdentifier(org.loveandroid.androidtest:drawable/icon",null,null);
if(indentify>0){
icon = resources.getDrawable(indentify);
}
第一个参数格式是:包名 + : + 资源文件夹名
+ / +资源名;是这种格式 然后其他的可以为null
(2)方式二
Resources resources = context.getResources();
int indentify= getResources().getIdentifier("icon", "drawable", "org.anddev.android.testproject");
第一个参数为ID名,第二个为资源属性是ID或者是Drawable,第三个为包名。
主要有两种方法:
(1)方式一
Resources resources = context.getResources();
int indentify = resources.getIdentifier(org.loveandroid.androidtest:drawable/icon",null,null);
if(indentify>0){
icon = resources.getDrawable(indentify);
}
第一个参数格式是:包名 + : + 资源文件夹名
+ / +资源名;是这种格式 然后其他的可以为null
(2)方式二
Resources resources = context.getResources();
int indentify= getResources().getIdentifier("icon", "drawable", "org.anddev.android.testproject");
第一个参数为ID名,第二个为资源属性是ID或者是Drawable,第三个为包名。
相关文章推荐
- Android使用getIdentifier()获取资源Id的方法
- 【我的Android进阶之旅】Android使用getIdentifier()方法根据资源名来获取资源id
- 使用getIdentifier()获取资源Id
- 使用getIdentifier()获取资源Id
- Android使用getIdentifier()获取资源Id
- phpcms v9使用GET调用指定id文章内容、页面数据方法(get标签什么方法)
- 使用getIdentifier()获取资源Id
- 使用getIdentifier()获取资源Id
- [android ui]使用getIdentifier()获取资源Id
- WP8 真机调试出现 指定的通信资源(端口)已由另一个应用程序使用 的解决方法
- Android 利用getIdentifier()方法获取资源ID
- phpcms v9使用GET调用指定id文章内容、页面数据方法
- 当应用继承ContentProvider类,并重写该类用于提供数据和存储数据的方法,就可以向其他应用共享其数据。 虽然使用其他方法也可以对外共享数
- Android使用getIdentifier()获取资源Id
- 开发记录:使用 array_column把id变作键名的方法,比foreach方便了
- springboot中通用mapper结合mybatis generator的使用 通用mapper是为了方便开发人员对单表进行crud操作而产生的一套通用方法。 通用mapper只支持单表操作,可以
- 使用getIdentifier()获取资源Id (根据Id的名字直接定位取到资源)
- 使用getIdentifier()获取资源Id
- Android中使用反射通过资源名字找到资源ID的方法
- 细聊分布式ID生成方法的实现(一个可以使用10年的序列生成器)