资源数组

use*_*016 24 string android android-xml android-resources

有没有办法在XML中定义一个元素是资源引用的数组?例如(它不起作用,但它解释了我想要的):

<integer-array name="actions_images">
    <item>@drawable/pencil</item>
    <item>@drawable/pencil</item>
    <item>@drawable/pencil</item>
    <item>@drawable/pencil</item>
    <item>@drawable/pencil</item>
    <item>@drawable/pencil</item>
</integer-array>
Run Code Online (Sandbox Code Playgroud)

Tho*_*alc 6

如果我正确理解你的问题,我想我知道一个解决方法(因为通过getResources()访问它们.getIntArray()不起作用).(你可以在这里阅读更多内容,这是我采取解决方法的来源.)

TypedArray ar = context.getResources().obtainTypedArray(R.array.my_array);
int len = ar.length();     
int[] resIds = new int[len];     
for (int i = 0; i < len; i++)     
    resIds[i] = ar.getResourceId(i, 0);

ar.recycle();                       
// Do stuff with resolved reference array, resIds[]...     
for (int i = 0; i < len; i++)     
    Log.v (TAG, "Res Id " + i + " is " + Integer.toHexString(resIds[i]));
Run Code Online (Sandbox Code Playgroud)