"res/values" 아래에 "arrays.xml" 파일을 생성한다.

 

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="title_array">
        <item>@string/title1</item>
        <item>@string/title2</item>
        <item>@string/title3</item>
        <item>@string/title4</item>
    </string-array>

    <string-array name="icon_array">
        <item>@drawable/ic_1</item>
        <item>@drawable/ic_2</item>
        <item>@drawable/ic_3</item>
        <item>@drawable/ic_4</item>
    </string-array
    
    <string-array name="color_array">
        <item>@color/black</item>
        <item>@color/white</item>
        <item>@color/red</item>
    </string-array>
</resources>

 파일 내에 필요한 데이터를 작성한다. 문자열이나 이미지, 색상 리소스가 들어갈 수 있으며 값을 그대로 작성해도 되고 strings.xml, colors.xml에 작성한 값을 읽어와도 된다.

 

 

리소스 읽어 오기

 리소스를 읽어올 때는 name 값을 사용한다.

 

 문자열 읽기

String[] arr = getResources().getStringArray(R.array.title_array);

 

 

이미지 리소스 읽기

TypedArray typeArr = getResources().obtainTypedArray(R.array.icon_array);

for(int i = 0; i < typeArr.length(); i++)
	typeArr.getDrawable(i);

 

 

색상 코드 읽기

int[] colorArr = getResources().getIntArray(R.array.color_array);

+ Recent posts