【发布时间】:2013-04-28 12:00:59
【问题描述】:
在我的应用程序中,我需要在不想保留引用 R 的地方获取一些位图可绘制对象。所以我创建了一个类DrawableManager 来管理drawables。
public class DrawableManager {
private static Context context = null;
public static void init(Context c) {
context = c;
}
public static Drawable getDrawable(String name) {
return R.drawable.?
}
}
然后我想在这样的地方按名称获取可绘制对象(car.png 放在 res/drawables 中):
Drawable d= DrawableManager.getDrawable("car.png");
但是如您所见,我无法通过名称访问资源:
public static Drawable getDrawable(String name) {
return R.drawable.?
}
还有其他选择吗?
【问题讨论】: