android代码中动态获取资源ID
2013-05-22 20:27
405 查看
ResourcesId.zip:http://download.csdn.net/detail/victoryckl/5430775
https://github.com/victoryckl/ResourcesId.git
动态获取资源ID,
避免打包成jar文件,或者移植代码到别的APK中时,R.java import错误。
https://github.com/victoryckl/ResourcesId.git
动态获取资源ID,
避免打包成jar文件,或者移植代码到别的APK中时,R.java import错误。
package com.example.resid; import android.content.Context; import android.content.res.Resources; public class ResourcesId { private static final String TAG = "ResourcesId"; private static Context mContext; private static Resources mResources; private static String mPackageName; private ResourcesId() {} private static class ResourcesIdHolder { private static ResourcesId instance = new ResourcesId(); } private static void setContext(Context context) { if (context != null) { mContext = context.getApplicationContext(); mResources = mContext.getResources(); mPackageName = mContext.getPackageName(); } } public static ResourcesId getInstance(Context context) { ResourcesIdHolder.instance.setContext(context); return ResourcesIdHolder.instance; } public int getResourcesId(String defType, String name) { if (mResources != null) { return mResources.getIdentifier(name, defType, mPackageName); } return 0; } public static int getResourcesId(Context context, String defType, String name) { return ResourcesId.getInstance(context).getResourcesId(defType, name); } }
相关文章推荐
- android换肤功能 如何动态获取控件中背景图片的资源id?
- Android中获取资源 id 及资源 id 的动态获取
- android换肤功能中,如何动态获取控件中背景图片的资源id?
- 通过字段名称动态获取资源的id(将Android工程做成jar包和资源文件)
- Android:资源 id 及资源 id 的动态获取
- Android:资源id及资源id的动态获取
- Android:资源 id 及资源 id 的动态获取
- Android 动态加载APK--代码安装、获取资源及Intent调用已安装apk
- Android:资源 id 及资源 id 的动态获取
- Android 动态获取资源的ID
- Android:资源 id 及资源 id 的动态获取
- Android:资源 id 及资源 id 的动态获取
- Android 动态加载APK--代码安装、获取资源及Intent调用已安装apk
- Android 动态获取资源ID
- android利用java反射机制动态获取资源ID
- Android:资源 id 及资源 id 的动态获取
- Android:资源 id 及资源 id 的动态获取
- Android:资源 id 及资源 id 的动态获取
- Android通过反射动态获取资源Id
- android动态获取资源ID