Android:从Resources对象中检索所有Drawable资源 [英] Android: retrieving all Drawable resources from Resources object

查看:197
本文介绍了Android:从Resources对象中检索所有Drawable资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Android项目中,我想循环遍历 Drawable 资源的整个集合。通常,您只能通过其ID使用以下内容检索特定资源:

In my Android project, I want to loop through the entire collection of Drawable resources. Normally, you can only retrieve a specific resource via its ID using something like:

InputStream is = Resources.getSystem().openRawResource(resourceId)

但是,我想得到所有 Drawable 资源,其中我不会预先知道他们的ID。有没有一个集合我可以循环,或者一种方式来获得资源ID的列表给定的资源在我的项目?

However, I want to get all Drawable resources where I won't know their ID's beforehand. Is there a collection I can loop through or perhaps a way to get the list of resource ID's given the resources in my project?

或者,有一种方式为我Java从 R.drawable 静态类中提取所有属性值?

Or, is there a way for me in Java to extract all property values from the R.drawable static class?

推荐答案

p>如果你发现自己想这样做,你可能是误用资源系统。查看资产和 AssetManager 如果你想迭代包含在.apk中的文件。

If you find yourself wanting to do this you're probably misusing the resource system. Take a look at assets and AssetManager if you want to iterate over files included in your .apk.

这篇关于Android:从Resources对象中检索所有Drawable资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆