android 在xml中管理图片资源和调用方法

来源:互联网 发布:系统数据对接 编辑:程序博客网 时间:2024/05/19 02:00


首先 在xml中这样配置

<array name = "drawer_icon_normal">
        <item>@drawable/drawer_home_normal</item>
        <item>@drawable/drawer_follow_normal</item>
        <item>@drawable/drawer_collect_normal</item>
        <item>@drawable/drawer_register_normal</item>
        <item>@drawable/drawer_explore_normal</item>
    </array>



然后在代码中调用如下:

TypedArray array = context.getResources().obtainTypedArray(R.array.drawer_icon_normal);
    for (int i= 0; i< array.length(); i++) {
        drawables_normal[i$] = array.getResourceId(i$, R.drawable.default_profile);
    }
    array.recycle();

阅读全文
0 0
原创粉丝点击