Accessing resources programmatically

前端 未结 3 547
[愿得一人]
[愿得一人] 2020-12-10 07:36

Is it possible to receive the resource-ids being kept by a as an int[] programmatically without referring to the resource-class R?



        
3条回答
  •  猫巷女王i
    2020-12-10 08:13

    public static final int[] getResourceDeclareStyleableIntArray(String name) {
        int[] result = null;
        try {
            result = (int[]) R.styleable.class.getField(name).get(R.styleable.class);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return result;
    }
    

提交回复
热议问题