get Drawable By Id from resource - Android App

Android examples for App:Resource

Description

get Drawable By Id from resource

Demo Code

/**/* ww  w . jav a2s  .  c om*/
 * Created by slynero at 2:23 on 14-7-18.
 * Copyright (c) 2014 FineSoft. All rights reserved.
 */
//package com.java2s;
import android.content.Context;
import android.graphics.drawable.Drawable;

public class Main {
    public static Drawable getDrawableById(Context paramContext,
            String paramString) {
        return paramContext.getResources().getDrawable(
                getDrawableId(paramContext, paramString));
    }

    public static int getDrawableId(Context paramContext, String paramString) {
        return paramContext.getResources().getIdentifier(paramString,
                "drawable", paramContext.getPackageName());
    }
}

Related Tutorials