Rename files to lowercase

As you probably now, your application’s images that are in the drawable directory must be named in lowercase.

Unfortunately this is not true for the iPhone applications. A big portion of my job is to develop Android apps using resources from existing iPhone apps. In order to be quick and efficient, I wrote this bash script that renames all your files in your current directory to lowercase, creates a new folder named 2x (which contains the large images) and removes the @2x extension.

for i in `find .`; do mv -v $i `echo $i | tr '[A-Z]' '[a-z]'`; done
mkdir 2x
mv *2x.png 2x/
cd 2x/
for i in `find .`; do mv -v $i `echo $i | tr -d '@2x'`; done

Please have a backup before using it!

Share

Load a resource by name

Suppose you have an image named “test.png” in your res/drawable directory.

You will probably use is as this:

Drawable mDrawable = getResources().getDrawable(R.drawable.test);

But what if you want to dynamically load the drawable by it’s name?

You can use this:

String mDrawableName = "test";
int resID = getResources().getIdentifier(mDrawableName , "drawable", getPackageName());
Drawable mDrawable = getResources().getDrawable(resID);
Share