Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.content.res.TypedArray; import android.support.annotation.AttrRes; public class Main { public static int resolveDimension(Context context, @AttrRes int attr) { return resolveDimension(context, attr, -1); } private static int resolveDimension(Context context, @AttrRes int attr, int fallback) { TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { attr }); try { return a.getDimensionPixelSize(0, fallback); } finally { a.recycle(); } } }