Resource 형식 | 폴더(/res/) | 파일명 (권장사항) | element / 비고 |
String | values | strings.xml | <string> |
String Array | values | arrays.xml | <string-array> |
Color value | values | colors.xml | <color> |
Dimension | values | dimens.xml | <dimen> |
Simple drawables | values | drawables.xml | <drawable> |
Style & Theme | values | styles.xml | <style> |
Bitmap graphics | drawable | *.png, *.jpg, *.xml | 이미지파일, 표시물을 정의하는 xml 파일 |
Animations | anim | *.xml | |
Menu | menu | *.xml | <menu> |
XML | xml | *.xml | |
Raw file | raw | *.mp3, *.mp4, *.txt | |
Layout | layout | .xml | |
1. string
<string name="category1">도서</string>
<string name="category2">음반</string>
String myResourceString = getResources().getString(R.string.category1);
2. string-array
<string-array name="fruits">
<item>사과</item>
<item>오렌지</item>
<item>수박</item>
</string-array>
<string-array name="coworker">
<item>@string/name1</item>
<item>@string/name2</item>
<item>@string/name3</item>
</string-array>
String[] aGreens = getResources().getStringArray(R.array.fruits);
3. color
<color name="backgroundColor">#ff0000</color>
int myBackColor = getResources().getColor(R.color.backgroundColor);
4. dimension
<dimen name="menuTextSize">18pt</dimen>
float textSize = getResources().getDimension(R.dimen.menuTextSize);
또는
<TextView ......... android:textSize="@dimen/menuTextSize" />
5. drawable
<!-- 빨간 사각형 -->
<drawable name="redRect">#F00</drawable>
ColorDrawable myDraw = (ColorDrawable)getResources().getDrawable(R.drawable.redRect);
6. image
/res/drawable/egg.png
ImageView eggImage = (ImageView)findViewById(R.id.ImageView01);
eggImage.setImageResource(R.drawable.egg);
반응형
'Program > Android Java' 카테고리의 다른 글
안드로이드 - OptionMenu : 단말기 Menu 버튼 클릭하면 나오는 메뉴 (0) | 2012.06.12 |
---|---|
안드로이드 - Animation : XML 파일로 시퀀스 설정 (0) | 2012.06.12 |
안드로이드 - 웹에있는 mp3 플레이 하기 (0) | 2012.06.12 |
[android] C2DM을 이용한 push notification (0) | 2012.06.12 |
스크롤뷰내 리스트뷰 터치 가능하게 (0) | 2012.05.17 |