Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    /**
     *
     * @param context Context
     * @param name String
     * @return int
     */
    public static int getPixelSizeByName(Context context, String name) {
        Resources resources = context.getResources();
        int resourceId = resources.getIdentifier(name, "dimen", "android");
        if (resourceId > 0) {
            return resources.getDimensionPixelSize(resourceId);
        }
        return 0;
    }
}