码迷,mamicode.com
首页 > 移动开发 > 详细

android资源:颜色、数组、尺寸简单案例

时间:2015-07-24 09:14:54      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:

一、颜色

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>
View Code

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="颜色资源测试(深绿色)" />
View Code

 

二、数组

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>
View Code

 

2、在layout\main.xml中引用

技术分享
    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:entries="@array/cityArr" >
    </ListView>
View Code

 

3、在activty中调用

技术分享
String[] cityArr = getResources().getStringArray(R.array.cityArr);
for(String city:cityArr){
Log.v("info", "城市:"+city);
}
View Code

 

三、尺寸

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>
View Code

 

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" />
View Code

 

android资源:颜色、数组、尺寸简单案例

标签:

原文地址:http://www.cnblogs.com/2015android/p/4672333.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!