标签:
//直接调用Activity的getResource()方法来获取Resource对象
Resource res = getResource();
//获取字符串资源
String mainTitle = res.getText(R.string.main_title);
//获取Drawable资源
Drawable logo = res.getDrawable(R.drawable.logo);
//获取数组资源
int[] arr = res.getIntArray(R.array.books);
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">字符串、数字、尺寸资源</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="颜色名称">#F00</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="尺寸名称">9dp</string>
<dimen name="cell_width">60dp</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- 定义一个Drawable数组 -->
<array name="plain_arr">
<item>@color/c1</item>
<item>@color/c2</item>
<item>@color/c3</item>
</array>
<!-- 定义字符串数组 -->
<string-array name="string_arr">
<item>@string/c1</item>
<item>@string/c2</item>
<item>@string/c3</item>
</string-array>
<!-- 定义字符串数组 -->
<string-array name="books">
<item>字符串1</item>
<item>字符串2</item>
<item>字符串3</item>
</string-array>
</resources>
String[] texts = getResources().getStringArray(R.array.string_arr);
TypedArray icons = res.obtainTypedArray(R.array.plain_arr);
//使用颜色资源来设置文本框的背景色
text.setBackgroundDrawable(icons.getDrawable(position));
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<!--定义了一个样式,指定字体大小、字体颜色 --->
<style name = "style1">
<item name="android:textSize">20sp</item>
<item name="android:textColor">#00d</item>
</style>
<style name = "style2" parent="@style/style1">
<item name="android:background">#ee6</item>
<item name="android:padding">8dp</item>
<!--覆盖父类式中指定的属性-->
<item name = "android:textColor">#000</item>
</style>
</resources>
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name = "myTheme">
<item name="android:WindowNoTitle">true</item>
<item name="android:WindowFullscreen">true</item>
<item name="android:WindowFrame">@drawable/window_border</item>
<item name="android:WindowBackground">@drawable/star</item>
</style>
</resources>
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 指定获得焦点时的颜色 -->
<item android:state_focused="true"
android:color="#f44"/>
<!-- 指定失去焦点时的颜色 -->
<item android:state_focused="false"
android:color="#eee"/>
</selector>
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape=["rectangle"|"oval"|"line"|"ring"]>
<!-- 定义几何图形四个角的弧度-->
<corners
android:radius="integer"
android:topLeftRadius="integer"
android:topRightRadius="integer"
android:bottomLedtRadius="integer"
android:bottomRightRadius="integer"/>
<!-- 定义使用的渐变颜色填充-->
<gradient
android:angle=
"integer"android:centerX="integer"
android:centerY="integer"
- android:centerColor="integer"
- android:endColor="color"
- android:grandientRadius="integer"
- android:startColor="integer"
- android:type=["linear"|"radial"|"sweep"]
- android:usesLevel= ["true"|"false"] />
android:topRightRadius="integer"
<!-- 定义几何形状的内边距-->
<padding
android:left="integer"
android:top="integer"
android:right="integer"
android:bottom="integer"
/>- <!-- 定义几何形状的大小-->
<size
android:width="integer"
android:top="integer"
android:right="integer"
android:bottom="integer"
/>- <!-- 定义使用单种颜色填充-->
- <solid
- android:color="color" />
- <!-- 定义为几何形状绘制边框-->
- <stroke
- android:width="integer"
- android:color="color"
- android:dashWidth="integer"
- android:dashGap="integer" />
</shape>
标签:
原文地址:http://www.cnblogs.com/fruitbolgs/p/4243028.html