Android getIdentifier

/**
09. * Demo描述:
10. * 利用getIdentifier()方法获取资源ID
11. *
12. * 方法描述:
13. * getIdentifier(String name, String defType, String defPackage)
14. * 第一个参数:资源的名称
15. * 第二个参数:资源的类型(drawable,string等)
16. * 第三个参数:包名
17.

*/ 

具体方法: 

// 获取config 文件对应的资源ID

 int id = mContext.getResources().getIdentifier("config", "xml", action.getClass().getPackage().getName());

// 获取到的图片资源 drawableId

int drawableId = mContext.getResources().getIdentifier("ic_launcher","drawable", mContext.getPackageName());

//获取到的字符串资源 stringId

int stringId = mContext.getResources().getIdentifier("hello","string", mContext.getPackageName());

猜你喜欢

转载自jia-dojo.iteye.com/blog/2175617
今日推荐