获取arrays.xml中的图片以及颜色值

前端之家收集整理的这篇文章主要介绍了获取arrays.xml中的图片以及颜色值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

res/values/arrays.xml

<?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>

代码获取

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);

http://developer.android.com/guide/topics/resources/more-resources.html#TypedArray

原文链接:https://www.f2er.com/xml/295678.html

猜你在找的XML相关文章