从字符串数组中的android参考绘制 [英] Reference drawable from string-array in android

查看:194
本文介绍了从字符串数组中的android参考绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何引用从字符串XML文件绘制资源? 我想做的事情

how would I reference a drawable resource from the string xml file? I want to do

<string-array name="my_array">
<item>@drawable/my_image</item>
...

我将如何做呢?

How would I do that?

推荐答案

对于可绘IDS阵列,不使用字符串数组只需使用&LT;阵&GT;

for arrays of drawables ids, don't use string array just use <array>

然后使用它们,获得了 TypedArray 如果ID

then to use them, get a TypedArray if the ids

TypedArray images = getResources().obtainTypedArray(R.array.my_image_ids);
int resourceId = images.getResourceId(id, -1);

和当您使用资源ID和阵列就完成了循环利用,不要忘记

and don't forget when you're done with the resource id and array to recycle it

images.recycle();

这篇关于从字符串数组中的android参考绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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