get Resource Id - Android App

Android examples for App:Resource

Description

get Resource Id

Demo Code


//package com.java2s;

import android.content.Context;

import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;

public class Main {
    public static int getResourceId(Context context, String name,
            String type, String packageName) {
        Resources themeResources = null;
        PackageManager pm = context.getPackageManager();
        try {/*from   w  w w  .j a va 2 s .c o m*/
            themeResources = pm.getResourcesForApplication(packageName);
            return themeResources.getIdentifier(name, type, packageName);
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
        return 0;
    }
}

Related Tutorials