系统资源
资源res
Directory | Resource Type |
animator/ | XML files that define property animations. |
anim/ | XML files that define tween animations. (Property animations can also be saved in this directory, but the animator/ directory is preferred for property animations to distinguish between the two types.) |
color/ | XML files that define a state list of colors. See Color State List Resource |
drawable/ | Bitmap files (.png, .9.png, .jpg, .gif) or XML files that are compiled into the following drawable resource subtypes: · Bitmap files · Nine-Patches (re-sizable bitmaps) · State lists · Shapes · Animation drawables · Other drawables See Drawable Resources. |
layout/ | XML files that define a user interface layout. See Layout Resource. |
menu/ | XML files that define application menus, such as an Options Menu, Context Menu, or Sub Menu. See Menu Resource. |
raw/ | Arbitrary files to save in their raw form. To open these resources with a raw InputStream, call Resources.openRawResource() with the resource ID, which is R.raw.filename. However, if you need access to original file names and file hierarchy, you might consider saving some resources in the assets/ directory (instead of res/raw/). Files in assets/ are not given a resource ID, so you can read them only using AssetManager. |
values/ | XML files that contain simple values, such as strings, integers, and colors. Whereas XML resource files in other res/ subdirectories define a single resource based on the XML filename, files in the values/ directory describe multiple resources. For a file in this directory, each child of the <resources> element defines a single resource. For example, a <string> element creates an R.string resource and a <color> element creates an R.color resource. Because each resource is defined with its own XML element, you can name the file whatever you want and place different resource types in one file. However, for clarity, you might want to place unique resource types in different files. For example, here are some filename conventions for resources you can create in this directory: · arrays.xml for resource arrays (typed arrays). · colors.xml for color values · dimens.xml for dimension values. · strings.xml for string values. · styles.xml for styles. See String Resources, Style Resource, and More Resource Types. |
xml/ | Arbitrary XML files that can be read at runtime by calling Resources.getXML(). Various XML configuration files must be saved here, such as a searchable configuration. |
Caution: Never save resource files directly inside the res/ directory—it will cause a compiler error.
1.主题theme和控件风格style.xml
位于values/style
(1)窗体theme继承的主题--theme.xml
各种系统主题链接
http://henzil.easymorse.com/?p=364
设置各种控件的各种属性,如窗体的样式,背景色
<resources>
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="CustomTheme" parent = “@android:style/Theme.Dialog”> <item name="android:windowNoTitle">true</item> <item name="windowFrame">@drawable/screen_frame</item> <item name="windowBackground">@drawable/screen_background_white</item> </style> </resources> | ||
示例:
|
注:由parent标签标示继承父主题,在Activity中由android:theme引用主题
(2)控件stylle--style.xml
官方文档 <?xml version="1.0" encoding="utf-8"?> elements: <shape> 形状.必须为根元素 attributes: xmlns:android String. Required.定义在xmlnamespace中, 必须为"http://schemas.android.com/apk/res/android". android:shape 关键字。定义这个形状的类型,可定义形状如下:
下面的属性只被用于 android:shape="ring": android:innerRadius Dimension. 圆环的内部半径(中部的洞),可做为一个dimension值或dimension resource。 android:innerRadiusRatio Float. The radius for the inner part of the ring, expressed as a ratio of the ring's width. For instance, if android:innerRadiusRatio="5", then the inner radius equals the ring's width divided by 5. This value is overridden by android:innerRadius. Default value is 9. android:thickness Dimension. The thickness of the ring, as a dimension value or dimension resource. android:thicknessRatio Float. The thickness of the ring, expressed as a ratio of the ring's width. For instance, ifandroid:thicknessRatio="2", then the thickness equals the ring's width divided by 2. This value is overridden by android:innerRadius. Default value is 3. android:useLevel Boolean. "true" if this is used as a LevelListDrawable. This should normally be "false" or your shape may not appear. <corners> 为shape创建圆角,只被用于shape是一个rectangle。 属性: android:radius Dimension.所有角的弧半径, 是一个dimension或者是一个dimension resource.可以被以下几个属性覆盖。a android:topLeftRadius Dimension. 左上角。 android:topRightRadius Dimension. 右上角。 android:bottomLeftRadius Dimension. 左下角。 android:bottomRightRadius Dimension.右下角。 Note:每个角的半径必须大于1,或者没有规定圆角。如果想指定角不是圆角,可以用android:radius设置一个默认大于1的圆角弧 ,但是在后面覆盖你想的值,如果不想设定可以用0. <gradient> 指定一个渐变色。 attributes: android:angle Integer.渐变角度,0--左到右,90--底到上。必须是45的倍数,默认是0. android:centerX Float.渐变中心的X相对位置。(0-1.0)。 android:centerY Float. 渐变中心的Y相对位置。(0-1.0)。 android:centerColor Color.任选的界于开始于结束瑟之间的颜色色, as a hexadecimal value orcolor resource. android:endColor Color. The ending color, as a hexadecimal value or color resource. android:gradientRadius Float. The radius for the gradient. Only applied when android:type="radial". android:startColor Color. The starting color, as a hexadecimal value or color resource. android:type Keyword. 所应用的渐变模式类型。包括以下:
android:useLevel Boolean. "true" if this is used as a LevelListDrawable. <padding> Padding to apply to the containing View element (this pads the position of the View content, not the shape). attributes: android:left Dimension. Left padding, as a dimension value or dimension resource. android:top Dimension. Top padding, as a dimension value or dimension resource. android:right Dimension. Right padding, as a dimension value or dimension resource. android:bottom Dimension. Bottom padding, as a dimension value or dimension resource. <size> Shape的大小 属性: android:height Dimension. The height of the shape, as a dimension value or dimension resource. android:width Dimension. The width of the shape, as a dimension value or dimension resource. Note: The shape scales to the size of the container View proportionate to the dimensions defined here, by default. When you use the shape in an ImageView, you can restrict scaling by setting theandroid:scaleType to "center". <solid> Shape的填充色。 attributes: android:color Color. The color to apply to the shape, as a hexadecimal value or color resource. <stroke> Shape的描边。 属性: android:width Dimension. The thickness of the line, as a dimension value or dimension resource. android:color Color. The color of the line, as a hexadecimal value or color resource. android:dashGap Dimension. The distance between line dashes, as a dimension value or dimension resource. Only valid if android:dashWidth is set. android:dashWidth Dimension. The size of each dash line, as a dimension value or dimension resource. Only valid ifandroid:dashGap is set. example: XML file saved at res/drawable/gradient_box.xml: <?xml version="1.0" encoding="utf-8"?> This layout XML applies the shape drawable to a View: <TextView This application code gets the shape drawable and applies it to a View: Resources res = getResources();
|
3.尺寸dimens.xml
<resources>
<dimen name="notepad_margin">30dp</dimen>
</resources>
4.国际化string.xml
注:限定符(1)language:小写字母(en/ch)
(2)Region:r后加2个大写字母:(rUS)
5.attr.xml属性文档,供控件调用的属性
1)原理:在attrs.xml中添加控件在xml中可以设置的属性集合如<attr name = “android:text” format = “String”>属性,则我们在构建layout是调用自定义的控件时就可以调用在attrs.xml中所添加的属性如android:text = “hellow android”.当然在attrs.xml中定义的属性必须要有相应的基本控件来设置和获取。如text属性可以由一个TextView来实现,并提供set和get.
2)属性格式
name是属性名,format是属性的格式,有如下几种格式
reference---引用
color----颜色
boolean---布尔值
dimension---尺寸
float----浮点值
integer---整形值
string---字符串
fraction----百分数
enum
<attr name = “orientation”>
<enum name = “horizondtal” value = “0”/>
<enum name = “vertical ” value = “1”/>
</attr>
3)自定义命名空间:xmlns:[myspace]=“http://schemas;android.com/apk/res/包名”
包名是Manifest中的<manifest>节点处的包名
调用自定义命名空间的属性需要添加空间名如myspace:text
4)如何获取属性的值
A)TypedArray a = context.obtainStyledAttributes();
B)由TypedArray的getXXX()获取相应的值,如getText(),getDrawable();