Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将int[]转换为typedarray Android_Java_Android_Int_Typedarray - Fatal编程技术网

Java 如何将int[]转换为typedarray Android

Java 如何将int[]转换为typedarray Android,java,android,int,typedarray,Java,Android,Int,Typedarray,您正在传递一个id数组,其中只需要一个可绘制数组的id 请看这个例子 int[] imageIds = { R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4}; TypedArray icons = res.obtainTypedArray(int[]); /* this is not Working. */ @可抽出式/家用 @可绘制/设置 @可提取/注销 #FFFF0000 #FF00F

您正在传递一个id数组,其中只需要一个可绘制数组的id

请看这个例子

int[] imageIds = { R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4};

TypedArray icons = res.obtainTypedArray(int[]); /* this is not Working. */

@可抽出式/家用
@可绘制/设置
@可提取/注销
#FFFF0000
#FF00FF00
#FF0000FF
此应用程序代码检索每个数组,然后获取每个数组中的第一个条目:
Resources res=getResources();
TypedArray图标=res.obtainTypedArray(R.array.icons);
Drawable Drawable=图标。getDrawable(0);
TypedArray颜色=res.obtainTypedArray(R.array.colors);
int color=colors.getColor(0,0);
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <array name="icons">
        <item>@drawable/home</item>
        <item>@drawable/settings</item>
        <item>@drawable/logout</item>
    </array>
    <array name="colors">
        <item>#FFFF0000</item>
        <item>#FF00FF00</item>
        <item>#FF0000FF</item>
    </array>
</resources>
This application code retrieves each array and then obtains the first entry in each array:
Resources res = getResources();
TypedArray icons = res.obtainTypedArray(R.array.icons);
Drawable drawable = icons.getDrawable(0);

TypedArray colors = res.obtainTypedArray(R.array.colors);
int color = colors.getColor(0,0);