Example usage for android.content.res Resources getIdentifier

List of usage examples for android.content.res Resources getIdentifier

Introduction

In this page you can find the example usage for android.content.res Resources getIdentifier.

Prototype

public int getIdentifier(String name, String defType, String defPackage) 

Source Link

Document

Return a resource identifier for the given resource name.

Usage

From source file:Main.java

public static int getStatusBarHeight(Resources r) {
    int resourceId = r.getIdentifier("status_bar_height", "dimen", "android");
    return r.getDimensionPixelSize(resourceId);
}

From source file:Main.java

public static int getNavigationBarHeight(Resources r) {
    int resourceId = r.getIdentifier("navigation_bar_height", "dimen", "android");
    return r.getDimensionPixelSize(resourceId);
}

From source file:Main.java

public static int getNavBarHeight(Resources res) {
    int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        return res.getDimensionPixelSize(resourceId);
    }/*ww  w  . j  a v  a  2s .  c o  m*/
    return 0;
}

From source file:Main.java

public static int getResLayoutID(String resName) {
    Resources res = context.getResources();
    return res.getIdentifier(resName, "layout", context.getPackageName());
}

From source file:Main.java

public static int getResStyleID(String resName) {
    Resources res = context.getResources();
    return res.getIdentifier(resName, "style", context.getPackageName());
}

From source file:Main.java

public static int getResColorID(String resName) {
    Resources res = context.getResources();
    return res.getIdentifier(resName, "color", context.getPackageName());
}

From source file:Main.java

public static int getResRawID(String resName) {
    Resources res = context.getResources();
    return res.getIdentifier(resName, "raw", context.getPackageName());
}

From source file:Main.java

public static float getPxFromDimen(Context context, String resName) {
    Resources resources = context.getResources();
    int resId = resources.getIdentifier(resName, "dimen", context.getPackageName());
    if (resId <= 0)
        return -1;
    return resources.getDimension(resId);
}

From source file:Main.java

public static int getFacialIdentifier(Context context, String type) {
    if (TextUtils.isEmpty(type)) {
        return -1;
    }/* w  w  w.ja  v  a2s  . c o  m*/
    Resources res = context.getResources();
    int resId = res.getIdentifier(String.format("like_%s", type), "drawable", context.getPackageName());
    return resId;
}

From source file:Main.java

public static int getStatusBarHeight(Resources res) {
    int result = 0;
    int resourceId = res.getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        result = res.getDimensionPixelSize(resourceId);
    }//ww  w .ja v  a 2 s. c o m
    return result;
}