Android Drawable Create getDrawable(final Context context, final String packageName, final int resourceID)

Here you can find the source of getDrawable(final Context context, final String packageName, final int resourceID)

Description

get Drawable

Declaration

public static Drawable getDrawable(final Context context,
            final String packageName, final int resourceID) 

Method Source Code

//package com.java2s;

import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;

import android.graphics.drawable.Drawable;

public class Main {
    public static Drawable getDrawable(final Context context,
            final String packageName, final int resourceID) {
        Drawable drawable = null;/*  w w  w.jav a2  s. c  om*/
        Context remoteContext = null;

        try {
            remoteContext = context.createPackageContext(packageName, 0);
            drawable = remoteContext.getResources().getDrawable(resourceID);
        } catch (final NameNotFoundException e) {
            e.printStackTrace();
        }

        return drawable;
    }
}

Related

  1. loadDrawable(final String imageUrl, final ImageView imageView, final ImageCallback imageCallback)
  2. getDrawableById(Context paramContext, String paramString)
  3. getDrawableFromUrl(String url)
  4. getPressedDrawable(int color)
  5. getDrawableByName(Context ctx, String name)
  6. drawableToTransitionDrawable( Drawable drawable)
  7. createTempImageFile(Context context, Drawable drawable)
  8. loadImageFromUrl(String url)