安卓:从获取资源对象的所有可绘制资源资源、对象

2023-09-11 20:24:00 作者:请远离我i

在我的Andr​​oid项目,我想通过绘制对象资源的整个集合循环。通常情况下,你只能通过它的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)

不过,我想所有的绘制对象的资源,我的不会了解自己的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.