Java tutorial
//package com.java2s; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; public class Main { public static Drawable resolveDrawable(Context context, int attr) { return resolveDrawable(context, attr, null); } public static Drawable resolveDrawable(Context context, int attr, Drawable fallback) { TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { attr }); try { Drawable d = a.getDrawable(0); if (d == null && fallback != null) d = fallback; return d; } finally { a.recycle(); } } }