Android Utililty Methods Drawable Create

List of utility methods to do Drawable Create


The list of methods to do Drawable Create are organized into topic(s).


DrawableloadDrawable(final String imageUrl, final ImageView imageView, final ImageCallback imageCallback)
load Drawable
Log.d(TAG, "loadDrawable(), url = " + imageUrl);
if (imageCache.containsKey(imageUrl)) {
    SoftReference<Drawable> softReference = imageCache
    Drawable drawable = softReference.get();
    if (drawable != null) {
        Log.w(TAG, "loadDrawable(), find url incache: " + imageUrl);
        return drawable;
DrawablegetDrawableById(Context paramContext, String paramString)
get Drawable By Id
return paramContext.getResources().getDrawable(
        getDrawableId(paramContext, paramString));
DrawablegetDrawableFromUrl(String url)
get Drawable From Url
return Drawable.createFromStream(getRequest(url), null);
StateListDrawablegetPressedDrawable(int color)
get Pressed Drawable
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[] { R.attr.state_pressed },
        new ColorDrawable(color));
return drawable;
BitmapgetDrawableByName(Context ctx, String name)
get Drawable By Name
BitmapFactory.Options options = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeResource(
        ctx.getResources().getIdentifier(name, "drawable",
                ctx.getPackageName()), options);
return bitmap;
DrawablegetDrawable(final Context context, final String packageName, final int resourceID)
get Drawable
Drawable drawable = null;
Context remoteContext = null;
try {
    remoteContext = context.createPackageContext(packageName, 0);
    drawable = remoteContext.getResources().getDrawable(resourceID);
} catch (final NameNotFoundException e) {
return drawable;
TransitionDrawabledrawableToTransitionDrawable( Drawable drawable)
drawable To Transition Drawable
TransitionDrawable mBitmapDrawable = null;
try {
    if (drawable == null) {
        return null;
    mBitmapDrawable = new TransitionDrawable(new Drawable[] {
            new ColorDrawable(android.R.color.transparent),
            drawable });
FilecreateTempImageFile(Context context, Drawable drawable)
create Temp Image File
File cacheDir = context.getCacheDir();
File file = null;
try {
    if (!cacheDir.isDirectory() || !cacheDir.exists())
} catch (Exception e) {
            "Create Folder Error about Cache Directory",
DrawableloadImageFromUrl(String url)
load Image From Url
URL m;
InputStream i = null;
try {
    m = new URL(url);
    i = (InputStream) m.getContent();
} catch (MalformedURLException e1) {
} catch (IOException e) {