一、颜色
1、在values\color.xml中定义
<?xml version="1.0" encoding="utf-8"?> <resources> <!-- 白色 --> <color name="white">#FFFFFF</color> <!-- 象牙色 --> <color name="ivory">#FFFFF0</color> <!-- 亮黄色 --> <color name="lightyellow">#FFFFE0</color> <!-- 黄色 --> <color name="yellow">#FFFF00</color> <!-- 海绿色 --> <color name="seagreen">#2E8B57</color> <!-- 森林绿 --> <color name="forestgreen">#228B22</color> <!-- 亮海蓝色 --> <color name="lightseagreen">#20B2AA</color> </resources>
2、在layout\main.xml中引用
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/ivory" android:text="颜色资源测试(象牙色)" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/forestgreen" android:text="颜色资源测试(深绿色)" />
二、数组
1、在values\array.xml中定义
<?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="cityArr"> <item>北京</item> <item>上海</item> <item>广州</item> </string-array> </resources>
2、在layout\main.xml中引用
<ListView android:layout_width="wrap_content" android:layout_height="wrap_content" android:entries="@array/cityArr" > </ListView>
3、在activty中调用
String[] cityArr = getResources().getStringArray(R.array.cityArr); for(String city:cityArr){ Log.v("info", "城市:"+city); }
三、尺寸
1、在values\dimens.xml中定义
<?xml version="1.0" encoding="utf-8"?> <resources> <dimen name="text_width">500px</dimen> <dimen name="text_height">50px</dimen> </resources>
2、在layout\main.xml中引用
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:height="@dimen/text_height" android:text="尺寸资源测试width=500px" android:width="@dimen/text_width" />
原文:http://www.cnblogs.com/2015android/p/4672333.html