当我们获取网络数据的时候,解析之后往往都是一个字符串,而不是资源id,所有我们没有办法直接使用,只能通过名称来获取到资源id,

package com.example.administrator.demo;
import android.content.Context; /**
* Created by Administrator on 2017/8/27 0027.
*/
public class GetResourcesUtils{ /**
* 获取资源文件的id
*
* @param context
* @param resName
* @return
*/
public static int getId(Context context, String resName) {
return context.getResources().getIdentifier(resName, "id", context.getPackageName());
} /**
* 获取资源文件中string的id
*
* @param context
* @param resName
* @return
*/
public static int getStringId(Context context, String resName) {
return context.getResources().getIdentifier(resName, "string", context.getPackageName());
} /**
* 获取资源文件drable的id
*
* @param context
* @param resName
* @return
*/
public static int getDrableId(Context context, String resName) {
return context.getResources().getIdentifier(resName, "drable", context.getPackageName());
} /**
* 获取资源文件layout的id
*
* @param context
* @param resName
* @return
*/
public static int getLayoutId(Context context, String resName) {
return context.getResources().getIdentifier(resName, "layout", context.getPackageName());
} /**
* 获取资源文件style的id
*
* @param context
* @param resName
* @return
*/
public static int getStyleId(Context context, String resName) {
return context.getResources().getIdentifier(resName, "style", context.getPackageName());
} /**
* 获取资源文件color的id
*
* @param context
* @param resName
* @return
*/
public static int getColorId(Context context, String resName) {
return context.getResources().getIdentifier(resName, "color", context.getPackageName());
} /**
* 获取资源文件dimen的id
*
* @param context
* @param resName
* @return
*/
public static int getDimenId(Context context, String resName) {
return context.getResources().getIdentifier(resName, "dimen", context.getPackageName());
} /**
* 获取资源文件ainm的id
*
* @param context
* @param resName
* @return
*/
public static int getAnimId(Context context, String resName) {
return context.getResources().getIdentifier(resName, "anim", context.getPackageName());
} /**
* 获取资源文件menu的id
*/
public static int getMenuId(Context context, String resName) {
return context.getResources().getIdentifier(resName, "menu", context.getPackageName());
} }

最新文章

  1. [NOIP2012]国王游戏 题解
  2. 二模 (7) day2
  3. 【HTML5】炫丽的时钟效果Canvas绘图与动画基础练习
  4. java实现音频转换
  5. Linux学习系列之Linux入门(二)Vim学习
  6. 开发腾讯移动游戏平台SDK ios版Ane扩展 总结
  7. tomcat与resin的比较
  8. 【MFC学习笔记-作业8-蝴蝶飞~】【什么鬼作业】
  9. [转载]给10万pv的WordPress选择最便宜高可用的硬件以及WordPress高并发支持
  10. css中的media
  11. 剖析html对标准标签和自定义标签闭合与不闭合渲染问题
  12. iframe中的模态框遮罩父窗口原理
  13. MySql数据库第一天
  14. RPM包的版本号比较
  15. Linux 搜索日志信息
  16. Only one complex type allowed as argument to a web api controller action.
  17. Js参数值中含有单引号或双引号解决办法
  18. iphone6主板注释
  19. Linux系统 Centos6 安装
  20. python数据字典的操作

热门文章

  1. Commit message 的写法规范。本文介绍Angular 规范(
  2. jquery根据值设置radio和select选中状态
  3. 【我的Android进阶之旅】如何快速寻找Android第三方开源库在Jcenter上的最新版本
  4. 采购订单打印并预览PDF
  5. day9 文件的读取
  6. BCH码
  7. nginx3
  8. c语言URL通过Http下载mp3 格式
  9. 【Java】仿真qq尝试:用户注册(二)
  10. 002. MySQL复制操作