Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.content.Context;

import android.graphics.drawable.Drawable;

public class Main {
    public static Drawable getDrawable(Context context, String name) {
        Drawable drawable = context.getResources().getDrawable(getResourceId(context, name));
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        return drawable;
    }

    public static int getResourceId(Context context, String variableName) {
        try {
            return context.getResources().getIdentifier(variableName, "drawable", context.getPackageName());
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }
}