您的位置:首页 > 移动开发 > Android开发

android jar包方式获取资源

2015-08-16 15:59 543 查看
本文从其他博客摘录,我们常碰到将程式打包成jar方式发给别人调用,但在获取资源时用普的R.id方式会导致报异常(找不到)

public class Helper

{

    public static int getLayoutId(Context context ,String name)

    {

        return context.getResources().getIdentifier(name, "layout", context.getPackageName());

    }

    

    public static int getResId(Context context ,String name)

    {

        return context.getResources().getIdentifier(name,"id",context.getPackageName());

        

    }

    

    public static int getResDraw(Context context ,String name)

    {

        return context.getResources().getIdentifier(name,"drawable",context.getPackageName());

        

    }

    

    public static int getResStyle(Context context ,String name)

    {

        return context.getResources().getIdentifier(name,"style",context.getPackageName());

        

    }

    

    public static int getResStr(Context context ,String name)

    {

        return context.getResources().getIdentifier(name,"string",context.getPackageName());        

    }

    

    public static int getResXml(Context context ,String name)

    {

        return context.getResources().getIdentifier(name,"xml",context.getPackageName());        

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  jar 资源