我正在开发一个应用程序,将有数百个不同的图标(作为矢量图形)供用户选择。组织它们、保存它们并参考它们的最佳方法是什么?
发布于 2021-09-21 21:19:06
您不应该将它们放在数据库中,您必须将它们加载到静态int数组中,在那里可以保存图标在数据库中的位置或首选位置。将它们直接保存在数据库中的问题是,当您更新应用程序时,它会给您带来很多麻烦。
发布于 2021-09-22 20:31:05
我在这里找到了一个答案:Retrieving all Drawable resources from Resources object
使用字段数组查找所有绘图,并取出资源名称中的“图标”:
public ArrayList<Integer> loadDrawables() {
final Field[] drawables = R.drawable.class.getFields();
ArrayList<Integer> fieldOfIcons = new ArrayList<Integer>();
for (Field field : drawables) {
if (field.getName().contains("icon")) { //Gets all drawables with "icon" in the name and returns resource identifier
fieldOfIcons.add(getResources().getIdentifier(field.getName(),"drawable", getContext().getPackageName()));
}
}
return fieldOfIcons;https://stackoverflow.com/questions/69275558
复制相似问题