get Dimens Resource - Android App

Android examples for App:Resource

Description

get Dimens Resource

Demo Code


//package com.java2s;
import android.content.Context;

public class Main {

    public static int getDimensResource(Context ctx, String name) {
        String packageName = ctx.getPackageName();
        try {// ww  w  .j a  va 2  s.  c o m
            Object obj;
            obj = Class.forName(packageName + ".R$dimen").newInstance();
            return Class.forName(packageName + ".R$dimen")
                    .getDeclaredField(name).getInt(obj);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }
}

Related Tutorials