从Resources对象检索所有Drawable资源 [英] Retrieving all Drawable resources from Resources object
问题描述
在我的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?
推荐答案
如果发现自己想要这样做,可能是在滥用资源系统.看看资产和 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.
这篇关于从Resources对象检索所有Drawable资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!