android通过图片名称获取资源识别码

一个小工具类

package com.listviewtest;

import android.content.Context;

/**
 * 获取资源文件识别码
 */
public class IdentifierUtil {

	public static int getIdentifier(Context context, String type, String payId) {

		String packageName = context.getPackageName();
		return context.getResources().getIdentifier(payId, type, packageName);
	}

	public static int getDrawableIdentifier(Context context, String payId) {
		return getIdentifier(context, "drawable", payId);
	}
	
	public static int getStyleIdentifier(Context context, String payId) {
		return getIdentifier(context, "style", payId);
	}
}

猜你喜欢

转载自yunix.iteye.com/blog/2002258