You can load a drawing or bitmap by name. Here is an example:
public Drawable getImageByName(String nameOfTheDrawable, Activity a){ Drawable drawFromPath; int path = a.getResources().getIdentifier(nameOfTheDrawable, "drawable", "com.mycompany.myapp"); Options options = new BitmapFactory.Options(); options.inScaled = false; Bitmap source = BitmapFactory.decodeResource(a.getResources(), path, options); drawFromPath = new BitmapDrawable(source); return drawFromPath; }
You can, of course, return a Bitmap, rather than drawable.
Drawbale d = getImageByName ("mageFileName", this);
Lumis
source share