You could do something like this.-
public static Drawable getDrawable(String name) {
Context context = YourApplication.getContext();
int resourceId = context.getResources().getIdentifier(name, "drawable", YourApplication.getContext().getPackageName());
return context.getResources().getDrawable(id);
}
In order to access the context from anywhere, you may extend Application class.-
public class YourApplication extends Application {
private static YourApplication instance;
public YourApplication() {
instance = this;
}
public static Context getContext() {
return instance;
}
}
And map it in your Manifest
application
tag
android:name=".YourApplication"
....
.
stackoverflow.comm
No comments:
Post a Comment