get Drawable Asset - Android App

Android examples for App:Assets Image

Description

get Drawable Asset

Demo Code


//package com.java2s;
import android.content.Context;
import android.graphics.drawable.Drawable;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static Drawable getDrawableAsset(Context context, String path) {

        // Get input stream
        InputStream inputStream = null;
        try {/* w w w  .j a va2  s  .c o m*/
            inputStream = context.getAssets().open(path);
        } catch (IOException e) {
            e.printStackTrace();
        }
        // Load image as Drawable
        Drawable drawable = Drawable.createFromStream(inputStream, null);

        return drawable;
    }
}

Related Tutorials