get Drawable Id from res - Android App

Android examples for App:Resource

Description

get Drawable Id from res

Demo Code


import java.lang.reflect.Field;
import android.content.Context;
import android.util.Log;

public class Main{
    public static int getDrawableId(Context ctx, String resName) {
        Integer id = ctx.getResources().getIdentifier(resName, "drawable",
                ctx.getPackageName());//from  w  w  w  .  j a  va  2 s  .co m
        return id;
    }
    private static String getPackageName() {
        return ctx.getPackageName();
        //return "com.lostad.app";
    }
}

Related Tutorials