`

【翻译】(40)更多资源类型

 
阅读更多

【翻译】(40)更多资源类型

 

see

http://developer.android.com/guide/topics/resources/more-resources.html

 

原文见

http://developer.android.com/guide/topics/resources/more-resources.html

 

-------------------------------

 

More Resource Types

 

更多资源类型

 

This page defines more types of resources you can externalize, including:

 

本页定义你可以外部化的更多资源类型,包括:

 

* Bool

 

* 布尔型

 

XML resource that carries a boolean value.

 

XML资源,携带一个布尔型值。

 

* Color

 

* 颜色

 

XML resource that carries a color value (a hexadecimal color).

 

XML资源,携带一个颜色值(一个十六进制颜色)

 

* Dimension

 

* 尺寸

 

XML resource that carries a dimension value (with a unit of measure).

 

XML资源,携带一个尺寸值(带有一个度量单位)。

 

* ID

 

* 标识符(注:ID是IDentity的英文缩写)

 

XML resource that provides a unique identifier for application resources and components.

 

XML资源,为应用程序资源和组件提供一个唯一标识符。

 

* Integer

 

* 整型

 

XML resource that carries an integer value.

 

XML资源,携带一个整型值。

 

* Integer Array

 

* 整型数组

 

XML resource that provides an array of integers.

 

XML资源,携带一个整型数组。

 

* Typed Array

 

* 带类型数组

 

XML resource that provides a TypedArray (which you can use for an array of drawables).

 

XML资源,提供一个TypedArray(你可以使用它作为一个可绘画对象的数组)。

 

-------------------------------

 

Bool

 

布尔型

 

A boolean value defined in XML.

 

一个定义在XML中的布尔型值。

 

-------------------------------

 

Note: A bool is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). As such, you can combine bool resources with other simple resources in the one XML file, under one <resources> element.

 

注意:一个布尔型是一个简单资源,它使用name属性提供的值来引用(而非XML文件的名称)。因此,你可以组合布尔型资源和其它简单资源在一个XML文件中,放在一个<resources>元素下。

 

-------------------------------

 

* file location:

 

* 文件位置:

 

res/values/filename.xml

 

res/values/<文件名>.xml

 

The filename is arbitrary. The <bool> element's name will be used as the resource ID.

 

文件名是任意的。<bool>元素的名称将被用作资源ID。

 

* resource reference:

 

* 资源引用:

 

In Java: R.bool.bool_name

 

在Java中:R.bool.<布尔型名称>

 

In XML: @[package:]bool/bool_name

 

在XML中:@[<包名>:]bool/<布尔型名称>

 

* syntax:

 

* 语法:

 

-------------------------------

 

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <bool

        name="bool_name"

        >[true | false]</bool>

</resources>

 

-------------------------------

 

* elements:

 

* 元素:

 

* <resources>

 

Required. This must be the root node.

 

必需的。它必须是根节点。

 

No attributes.

 

无属性。

 

* <bool>

 

A boolean value: true or false.

 

一个布尔型:true或false。

 

* attributes:

 

* 属性:

 

* name

 

* 名称

 

String. A name for the bool value. This will be used as the resource ID.

 

字符串。布尔值的名称。它将被用作资源ID。

 

* example:

 

示例:

 

XML file saved at res/values-small/bools.xml:

 

保存为res/values-small/bools.xml的XML文件。

 

-------------------------------

 

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <bool name="screen_small">true</bool>

    <bool name="adjust_view_bounds">true</bool>

</resources>

 

-------------------------------

 

This application code retrieves the boolean:

 

这段应用程序代码取出布尔型:

 

-------------------------------

 

Resources res = getResources();

boolean screenIsSmall = res.getBoolean(R.bool.screen_small);

 

-------------------------------

 

This layout XML uses the boolean for an attribute:

 

这个布局XML对一个属性使用布尔型:

 

-------------------------------

 

<ImageView

    android:layout_height="fill_parent"

    android:layout_width="fill_parent"

    android:src="@drawable/logo"

    android:adjustViewBounds="@bool/adjust_view_bounds" />

 

-------------------------------

 

-------------------------------

 

Color

 

颜色

 

A color value defined in XML. The color is specified with an RGB value and alpha channel. You can use a color resource any place that accepts a hexadecimal color value. You can also use a color resource when a drawable resource is expected in XML (for example, android:drawable="@color/green").

 

一个定义在XML中的颜色值。颜色用RGB值和透明通道指定。你可以在任意接受十六进制颜色值的地方使用一个颜色资源。你还可以在XML中期待一个可绘画对象资源时使用一个颜色资源,(例如,android:drawable="@color/green")。

 

The value always begins with a pound (#) character and then followed by the Alpha-Red-Green-Blue information in one of the following formats:

 

这个值总是以一个井号(#)字符开头,然后跟着的是依照以下形式之一的透明-红-绿-蓝信息。

 

* #RGB

* #ARGB

* #RRGGBB

* #AARRGGBB

 

-------------------------------

 

Note: A color is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). As such, you can combine color resources with other simple resources in the one XML file, under one <resources> element.

 

注意:一个颜色是一个简单资源,它使用name属性提供的值来引用(而非XML文件的名称)。因此,你可以组合颜色资源和其它简单资源在一个XML文件中,放在一个<resources>元素下。

 

-------------------------------

 

* file location:

 

* 文件位置:

 

res/values/colors.xml

 

res/values/<颜色文件名>.xml

 

The filename is arbitrary. The <color> element's name will be used as the resource ID.

 

文件名是任意的。<color>元素的名称将被用作资源ID。

 

* resource reference:

 

* 资源引用:

 

In Java: R.color.color_name

 

在Java中:R.color.<颜色名称>

 

In XML: @[package:]color/color_name

 

在XML中:@[<包名>:]color/<颜色名称>

 

* syntax:

 

* 语法:

 

-------------------------------

 

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <color

        name="color_name"

        >hex_color</color>

</resources>

 

-------------------------------

 

* elements:

 

* 元素:

 

* <resources>

 

Required. This must be the root node.

 

必需的。它必须是根节点。

 

No attributes.

 

无属性。

 

* <color>

 

A color expressed in hexadecimal, as described above.

 

一个以十六进制表示的颜色,正如上面描述的那样。

 

* attributes:

 

* 属性:

 

* name

 

String. A name for the color. This will be used as the resource ID.

 

字符串。颜色的名称。它将被用作资源ID。

 

* example:

 

* 示例:

 

XML file saved at res/values/colors.xml:

 

保存为res/values/colors.xml的XML文件:

 

-------------------------------

 

<?xml version="1.0" encoding="utf-8"?>

<resources>

   <color name="opaque_red">#f00</color>

   <color name="translucent_red">#80ff0000</color>

</resources>

 

-------------------------------

 

This application code retrieves the color resource:

 

这段应用程序代码取出颜色资源:

 

-------------------------------

 

Resources res = getResources();

int color = res.getColor(R.color.opaque_red);

 

-------------------------------

 

This layout XML applies the color to an attribute:

 

这个布局XML应用颜色到一个属性:

 

-------------------------------

 

<TextView

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:textColor="@color/translucent_red"

    android:text="Hello"/>

 

-------------------------------

 

-------------------------------

 

Dimension

 

尺寸

 

A dimension value defined in XML. A dimension is specified with a number followed by a unit of measure. For example: 10px, 2in, 5sp. The following units of measure are supported by Android:

 

一个定义在XML中的尺寸值。一个尺寸用一个数字后跟一个度量单位来指定。例如:10px,2in,5sp。Android支持的后缀度量单位有:

 

* dp

 

Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi (dots per inch) screen, so 160dp is always one inch regardless of the screen density. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. You should use these units when specifying view dimensions in your layout, so the UI properly scales to render at the same actual size on different screens. (The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".)

 

密度无关像素——一个抽象的单位,它基于屏幕的物理密度。这些单位是相对于一个160 dpi(点每英寸)屏幕的,所以160dp总是一英寸,不管屏幕密度是什么。dp到像素的的比例将随屏幕密度而改变,但不一定是以直接的比例。你应该使用这些单位,当在你的布局中指定视图尺寸,所以用户界面会正确地缩放,在不同屏幕上以相同的实际大小来渲染。(编译器同时接受"dip"和"dp",虽然"dp"与"sp"更为一致。)

 

* sp

 

Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user's preference.

 

缩放无关像素——它像dp单位,但它还被用户的字体大小预设(注:喜好)缩放。当指定字体大小时建议你使用这个单位,使它们将对于屏幕密度和用户的预设来调整。

 

* pt

 

Points - 1/72 of an inch based on the physical size of the screen.

 

点——一英寸的1/72,基于屏幕的物理大小。(注:大多数Android教材翻译为磅,“磅”是音译,常用于字体大小。详见http://en.wikipedia.org/wiki/Point_(typography)和中文维基)

 

* px

 

Pixels - corresponds to actual pixels on the screen. This unit of measure is not recommended because the actual representation can vary across devices; each devices may have a different number of pixels per inch and may have more or fewer total pixels available on the screen.

 

像素——对应于屏幕上的实际像素。不建议用这个度量单位,因为实际的呈现可能是跨设备不同的;每种设备每英寸可能有不同数量的像素,并且在屏幕上可能有较多或较少总数的可用像素。

 

* mm

 

Millimeters - based on the physical size of the screen.

 

毫米——基于屏幕的物理大小。

 

* in

 

Inches - based on the physical size of the screen.

 

英寸——基于屏幕的物理大小

 

-------------------------------

 

Note: A dimension is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). As such, you can combine dimension resources with other simple resources in the one XML file, under one <resources> element.

 

注意:一个尺寸是一个简单值,它使用name属性提供的值来引用(而非XML文件的名称)。因此,你可以组合尺寸资源和其它简单资源在一个XML文件中,放在一个<resources>元素下。

 

-------------------------------

 

* file location:

 

* 文件位置:

 

res/values/filename.xml

 

res/values/<文件名>.xml

 

The filename is arbitrary. The <dimen> element's name will be used as the resource ID.

 

文件名是任意的。<dimen>元素的名称将被用作资源ID。

 

* resource reference:

 

* 资源引用:

 

In Java: R.dimen.dimension_name

 

在Java中:R.dimen.<尺寸名>

 

In XML: @[package:]dimen/dimension_name

 

在XML中:@[<包名>:]dimen/<尺寸名>

 

* syntax:

 

* 语法:

 

-------------------------------

 

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <dimen

        name="dimension_name"

        >dimension</dimen>

</resources>

 

-------------------------------

 

* elements:

 

* 元素:

 

* <resources>

 

Required. This must be the root node.

 

必需的。它必须是根节点。

 

No attributes.

 

无属性。

 

* <dimen>

 

A dimension, represented by a float, followed by a unit of measurement (dp, sp, pt, px, mm, in), as described above.

 

一个尺寸值,用一个浮点值表示,后跟着一个度量单位(dp,sp,pt,px,mm,in),正如上面描述的那样。

 

* attributes:

 

* 属性:

 

* name

 

String. A name for the dimension. This will be used as the resource ID.

 

字符串。尺寸的名称,它将被用作资源ID。

 

* example:

 

* 示例:

 

XML file saved at res/values/dimens.xml:

 

保存为res/values/dimens.xml的XML文件:

 

-------------------------------

 

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <dimen name="textview_height">25dp</dimen>

    <dimen name="textview_width">150dp</dimen>

    <dimen name="ball_radius">30dp</dimen>

    <dimen name="font_size">16sp</dimen>

</resources>

 

-------------------------------

 

This application code retrieves a dimension:

 

这段应用程序代码取出一个尺寸:

 

-------------------------------

 

Resources res = getResources();

float fontSize = res.getDimension(R.dimen.font_size);

 

-------------------------------

 

This layout XML applies dimensions to attributes:

 

这个布局XML应用一些尺寸到属性上:

 

-------------------------------

 

<TextView

    android:layout_height="@dimen/textview_height"

    android:layout_width="@dimen/textview_width"

    android:textSize="@dimen/font_size"/>

 

-------------------------------

 

-------------------------------

 

ID

 

标识符

 

A unique resource ID defined in XML. Using the name you provide in the <item> element, the Android developer tools create a unique integer in your project's R.java class, which you can use as an identifier for an application resources (for example, a View in your UI layout) or a unique integer for use in your application code (for example, as an ID for a dialog or a result code).

 

一个定义在XML中的唯一资源ID。使用你在<item>元素中提供的名称,Android开发者工具在你的工程的R.java类中创建一个唯一整数,你可以使用它作为一个应用程序资源的标识符(例如,你的用户界面布局中的一个View)或一个在你的应用程序代码中使用的唯一整型(例如,作为一个对话框的ID或一个结果代码)。

 

-------------------------------

 

Note: An ID is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). As such, you can combine ID resources with other simple resources in the one XML file, under one <resources> element. Also, remember that an ID resources does not reference an actual resource item; it is simply a unique ID that you can attach to other resources or use as a unique integer in your application.

 

注意:一个ID是一个简单资源,它使用name属性提供的值来引用(而非XML文件的名称)。因此,你可以组合ID资源和其它简单资源在一个XML文件中,在<resources>元素下。同时,记住一个ID资源不引用一个实际的资源条目;它简单地是一个唯一ID,你可以把它依附到其它资源或在你的应用程序中使用它作为一个唯一整数。

 

-------------------------------

 

* file location:

 

* 文件位置:

 

res/values/filename.xml

 

res/values/<文件名>.xml

 

The filename is arbitrary.

 

文件名是任意的。

 

* resource reference:

 

* 资源引用:

 

In Java: R.id.name

 

在Java中:R.id.<名称>

 

In XML: @[package:]id/name

 

在XML中:@[<包名>:]id/<名称>

 

* syntax:

 

* 语法:

 

-------------------------------

 

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <item

        type="id"

        name="id_name" />

</resources>

 

-------------------------------

 

* elements:

 

* 元素:

 

* <resources>

 

Required. This must be the root node.

 

必需的。它必须是根节点。

 

No attributes.

 

无属性。

 

* <item>

 

Defines a unique ID. Takes no value, only attributes.

 

定义一个唯一ID。不带值,只有属性。

 

* attributes:

 

* 属性:

 

* type

 

Must be "id".

 

必须是"id"。

 

* name

 

String. A unique name for the ID.

 

字符串。ID的唯一名称。

 

* example:

 

* 示例:

 

XML file saved at res/values/ids.xml:

 

保存为res/values/ids.xml的XML文件:

 

-------------------------------

 

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <item type="id" name="button_ok" />

    <item type="id" name="dialog_exit" />

</resources>

 

-------------------------------

 

Then, this layout snippet uses the "button_ok" ID for a Button widget:

 

然后,这个布局片段对一个Button部件使用"button_ok"这个ID。

 

-------------------------------

 

<Button android:id="@id/button_ok"

    style="@style/button_style" />

 

-------------------------------

 

Notice that the android:id value does not include the plus sign in the ID reference, because the ID already exists, as defined in the ids.xml example above. (When you specify an ID to an XML resource using the plus sign—in the format android:id="@+id/name"—it means that the "name" ID does not exist and should be created.)

 

注意android:id值在ID引用中不包含加号,因为ID已经存在,正如上面的ids.xml示例中所定义的那样。(当你使用加号指定一个ID到一个XML资源时——以android:id="@+id/<名称>"的格式——它的意思是"<名称>"这个ID不存在,应该被创建。)

 

As another example, the following code snippet uses the "dialog_exit" ID as a unique identifier for a dialog:

 

作为另一个示例,以下代码片段使用"dialog_exit"这个ID作为一个对话框的唯一标识符:

 

-------------------------------

 

showDialog(R.id.dialog_exit);

 

-------------------------------

 

In the same application, the "dialog_exit" ID is compared when creating a dialog:

 

在同一个应用程序中,"dialog_exit"这个ID在创建一个对话框时被比较:

 

-------------------------------

 

protected Dialog onCreateDialog(int)(int id) {

    Dialog dialog;

    switch(id) {

    case R.id.dialog_exit:

        ...

        break;

    default:

        dialog = null;

    }

    return dialog;

}

 

-------------------------------

 

-------------------------------

 

Integer

 

整型

 

An integer defined in XML.

 

一个定义在XML中的整型。

 

-------------------------------

 

Note: An integer is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). As such, you can combine integer resources with other simple resources in the one XML file, under one <resources> element.

 

注意:一个整型是一个简单资源,它使用name属性提供的值来引用(而非XML文件的名称)。因此,你可以组合整型资源和其它简单资源在一个XML文件中,放在一个<resources>元素中。

 

-------------------------------

 

* file location:

 

* 文件位置:

 

res/values/filename.xml

 

res/values/<文件名>.xml

 

The filename is arbitrary. The <integer> element's name will be used as the resource ID.

 

文件名是任意的。<integer>元素的名称将被用作资源ID。

 

* resource reference:

 

* 资源引用:

 

In Java: R.integer.integer_name

 

在Java中:R.integer.<整型名称>

 

In XML: @[package:]integer/integer_name

 

在XML中:@[<包名>:]integer/<整型名称>

 

* syntax:

 

* 语法:

 

-------------------------------

 

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <integer

        name="integer_name"

        >integer</integer>

</resources>

 

-------------------------------

 

* elements:

 

* 元素:

 

* <resources>

 

Required. This must be the root node.

 

必需的。它必须是根元素。

 

No attributes.

 

无属性。

 

* <integer>

 

An integer.

 

一个整型。

 

* attributes:

 

* 属性:

 

* name

 

String. A name for the integer. This will be used as the resource ID.

 

字符串。整型的名称。它必须被用作资源ID。

 

* example:

 

* 示例:

 

XML file saved at res/values/integers.xml:

 

保存为res/values/integers.xml的XML文件:

 

-------------------------------

 

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <integer name="max_speed">75</integer>

    <integer name="min_speed">5</integer>

</resources>

 

-------------------------------

 

This application code retrieves an integer:

 

这段应用程序代码取出一个整型:

 

-------------------------------

 

Resources res = getResources();

int maxSpeed = res.getInteger(R.integer.max_speed);

 

-------------------------------

 

-------------------------------

 

Integer Array

 

整型数组

 

An array of integers defined in XML.

 

一个定义在XML中的整型数组。

 

-------------------------------

 

Note: An integer array is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). As such, you can combine integer array resources with other simple resources in the one XML file, under one <resources> element.

 

注意:一个整型数组是一个简单资源,它使用name属性提供的值来引用(而非XML文件的名称)。因此。你可以组合整型数组和其它简单资源在一个XML文件中,放在一个<resources>元素下。

 

-------------------------------

 

* file location:

 

* 文件位置:

 

res/values/filename.xml

 

res/values/<文件名>.xml

 

The filename is arbitrary. The <integer-array> element's name will be used as the resource ID.

 

文件名是任意的。<integer-array>元素的名称将被用作资源ID。

 

* compiled resource datatype:

 

* 被编译的资源数据类型:

 

Resource pointer to an array of integers.

 

指向一个整型数组的资源指针。

 

* resource reference:

 

* 资源引用:

 

In Java: R.array.string_array_name

 

在Java中:R.array.<整型数组名称>(注:此处string_array_name疑有误,应作integer_array_name)

 

In XML: @[package:]array.integer_array_name

 

在XML中:@[<包名>:]array.<整型数组名称>

 

* syntax:

 

* 语法:

 

-------------------------------

 

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <integer-array

        name="integer_array_name">

        <item

            >integer</item>

    </integer-array>

</resources>

 

-------------------------------

 

* elements:

 

* 元素:

 

* <resources>

 

Required. This must be the root node.

 

必需的。它必须为根节点。

 

No attributes.

 

无属性。

 

* <string-array>

 

* <integer-array>(注:此处疑有误,应作<integer-array>)

 

Defines an array of integers. Contains one or more child <item> elements.

 

定义一个整型数组,包含一个或多个子<item>元素。

 

* attributes:

 

* 属性:

 

* android:name

 

String. A name for the array. This name will be used as the resource ID to reference the array.

 

字符串。数组的名称。这个名称将被用作资源ID来引用该数组。

 

* <item>

 

An integer. The value can be a referenced to another integer resource. Must be a child of a <integer-array> element.

 

一个整型。该值可以是一个指向另一个整型资源的引用。必须是<integer-array>的一个子元素。

 

No attributes.

 

无属性。

 

* example:

 

* 示例:

 

XML file saved at res/values/integers.xml:

 

保存为res/values/integers.xml的XML文件:

 

-------------------------------

 

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <integer-array name="bits">

        <item>4</item>

        <item>8</item>

        <item>16</item>

        <item>32</item>

    </integer-array>

</resources>

 

-------------------------------

 

This application code retrieves the integer array:

 

这段应用程序代码取出整型数组:

 

-------------------------------

 

Resources res = getResources();

int[] bits = res.getIntArray(R.array.bits);

 

-------------------------------

 

-------------------------------

 

Typed Array

 

带类型的数组

 

A TypedArray defined in XML. You can use this to create an array of other resources, such as drawables. Note that the array is not required to be homogeneous, so you can create an array of mixed resource types, but you must be aware of what and where the data types are in the array so that you can properly obtain each item with the TypedArray's get...() methods.

 

一个定义在XML中的TypedArray。你可以使用它来创建其它资源的数组,诸如可绘画对象。注意数组不需要是同质的,所以你可以创建一个混合资源类型的数组,但你必须意识到在数组中数据类型是什么和在哪里,以使你可以用TypedArray的get...()方法正确地获取每个条目。

 

-------------------------------

 

Note: A typed array is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file). As such, you can combine typed array resources with other simple resources in the one XML file, under one <resources> element.

 

注意:一个带类型的数组是一个简单资源,它使用name属性提供的值来引用(而非XML文件的名称)。因此,你可以组合带类型的数组资源和其它简单资源在一个XML文件中,放在一个<resources>元素。

 

-------------------------------

 

* file location:

 

* 文件位置:

 

res/values/filename.xml

 

res/values/<文件名>.xml

 

The filename is arbitrary. The <array> element's name will be used as the resource ID.

 

文件名是任意的。<array>元素的名称将被用作资源ID。

 

* compiled resource datatype:

 

* 被编译的资源数据类型:

 

Resource pointer to a TypedArray.

 

指向一个TypedArray的资源指针。

 

* resource reference:

 

* 资源引用:

 

In Java: R.array.array_name

 

在Java中:R.array.<数组名称>

 

In XML: @[package:]array.array_name

在XML中:@[<包名>:]array.<数组名称>

 

* syntax:

 

* 语法:

 

-------------------------------

 

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <array

        name="integer_array_name">

        <item>resource</item>

    </array>

</resources>

 

-------------------------------

 

* elements:

 

* 元素:

 

* <resources>

 

Required. This must be the root node.

 

必需的。它必须是根节点。

 

No attributes.

 

无属性。

 

* <array>

 

Defines an array. Contains one or more child <item> elements.

 

定义一个数组。包含一个或多个子<item>元素。

 

* attributes:

 

* 属性:

 

* android:name

 

String. A name for the array. This name will be used as the resource ID to reference the array.

 

字符串。数组的名称。这个名称将被用作资源ID以引用该数组。

 

* <item>

 

A generic resource. The value can be a reference to a resource or a simple data type. Must be a child of an <array> element.

 

一个泛型资源。值可以是指向一个资源的引用或一个简单数据类型。必须是一个<array>元素的子元素。

 

No attributes.

 

无属性。

 

* example:

 

* 示例:

 

XML file saved at res/values/arrays.xml:

 

保存为res/values/arrays.xml的XML文件:

 

-------------------------------

 

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <array name="icons">

        <item>@drawable/home</item>

        <item>@drawable/settings</item>

        <item>@drawable/logout</item>

    </array>

    <array name="colors">

        <item>#FFFF0000</item>

        <item>#FF00FF00</item>

        <item>#FF0000FF</item>

    </array>

</resources>

 

-------------------------------

 

This application code retrieves each array and then obtains the first entry in each array:

 

这段应用程序代码取出每个数组,然后获取每个数组的第一个条目:

 

-------------------------------

 

Resources res = getResources();

TypedArray icons = res.obtainTypedArray(R.array.icons);

Drawable drawable = icons.getDrawable(0);

 

TypedArray colors = res.obtainTypedArray(R.array.colors);

int color = colors.getColor(0,0);

 

-------------------------------

 

Except as noted, this content is licensed under Apache 2.0. For details and restrictions, see the Content License.

 

除特别说明外,本文在Apache 2.0下许可。细节和限制请参考内容许可证。

 

Android 4.0 r1 - 18 Jan 2012 22:14

 

-------------------------------

 

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

 

(此页部分内容基于Android开源项目,以及使用根据创作公共2.5来源许可证描述的条款进行修改)

 

(本人翻译质量欠佳,请以官方最新内容为准,或者参考其它翻译版本:

* ソフトウェア技術ドキュメントを勝手に翻訳

http://www.techdoctranslator.com/android

* Ley's Blog

http://leybreeze.com/blog/

* 农民伯伯

http://www.cnblogs.com/over140/

* Android中文翻译组

http://androidbox.sinaapp.com/


分享到:
评论

相关推荐

    数据字典元数据(常见三千种字段命名缩写及规范,包括词根词素).rar

    1、资源内容:整理了近千种开发中常见的字段英文命名、字段名缩写、几乎不需要去因汉字去翻译成英文再去缩写。 2、使用场景:开发时由汉字关键字去检索对应的英文...6、更多内容包括动词等其他类型数据字段可详见资源;

    rfc中文文档目录,包含部分翻译

    RFC40 关于未来协议的更多注解 RFC41 IMP-IMP 通讯信息 RFC42 信息数据类型 RFC43 被提议的会议 RFC45 关于未来协议的更多注解 RFC53 官方协议机构 RFC58 逻辑信息同步 RFC60 简单的 NCP 协议 RFC63 迟来的网络...

    Java资源包01

    使用redis作缓存时,支持list类型的高级数据结构,更适合论坛帖子列表这种类型的数据 5. 支持混合使用redis缓存和memcached缓存。可以将列表数据缓存到redis中,其他kv结构数据继续缓存到memcached 6. 支持redis的...

    超级好的tensorflow文档资源,分享出来.zip

    如果更多的数据科学家开始使用 Google 的系统来从事机器学习方面的研究,那么这将有利于 Google 对日益发展的机器学习行业拥有更多的主导权。 为了让国内的技术人员在最短的时间内迅速掌握这一世界领先的 AI 系统,...

    谷歌开源神经机器翻译模型底层框架seq2seq.zip

    谷歌表示,它使开发者试验 seq2seq 模型变得更方便,更容易达到一流的效果。另外,tf-seq2seq 的代码库很干净并且模块化,保留了全部的测试覆盖,并把所有功能写入文件。  该框架支持标准 seq2seq 模型的多种配置...

    基于SpringBoot+Vue的智慧外贸平台(源码+部署说明+系统介绍+源码解释).zip

    通过逐行分析源码,我们对系统的技术实现、API设计、业务逻辑等进行深入解读和分析,帮助开发者更好地理解源码和在其基础上进行二次开发,并提供更多开发思路和技巧。 总之,本资源适合对SpringBoot、Vue、外贸平台...

    leetcode递归专题-resources:资源

    (每个类别的更多边界类别和问题) 面试角 (30 天计划涵盖的问题列表) 学习冲刺1 初学者跟踪(二进制搜索和递归!) (资源) (实践) (实践) (实践) (比赛) 中级轨道((用户输入/输出、循环、条件、数据...

    Csharp导出到EXCEL表格多sheet与打包软件

    - 更多支持的功能: 1、用于软件升级的更新器 2、控制面板小程序 3、支持安装前后的镜像中制作安装包的 Advanced Repackager 4、游戏、软件、试用授权 5、Windows Mobile/CE 安装程序 6、导入其他 MSI 文件、...

    ESM_ArcSight控制台用户指南(中文翻译版—Zephyr)_6.11.0 .pdf

    获得更多帮助 31 控制控制台 31 使用网络工具 33 运行一个工具命令 34 添加或编辑工具 35 保持知情 37 确认通知 37 使用笔记 38 许可证追踪 39 许可证跟踪通知 39 许可证状态跟踪的标准报表 39 使用文件菜单 40 使用...

    人事工资管理系统java源码-DW-using-MongoDB:使用MongoDB设计数据仓库所需的所有信息

    查看更多: 查看更多: String - 这是最常用的数据类型来存储数据。 MongoDB 中的字符串必须是 UTF-8 有效的。 Integer - 此类型用于存储数值。 整数可以是 32 位或 64 位,具体取决于您的服务器。 Boolean - 此类型...

    基于云计算的服务器虚拟化研究-.docx

    1 云计算特点分析 1.1 本钱节约 不同用户对资源的需求度存在一定差异,通过云计算可以实现满足不同用户群体对资源的应用需求,且与购置大量IT资源方式相比,应计算用户可以节约更多本钱。对于局部用户,仅需要某种...

    python-3.7.0b5下載

    Python 3.7.0 重大功能改进 那么,这次新发布的Python 3.7.0 有哪些重要的改进呢?总的来说, 新的syntax功能: PEP 563,推迟了类型注释(type annotations)的评估 ...等等优化,还有更多。

    msi 打包安装工具_AdvancedInstaller 破解版

    - 更多支持的功能: 1、用于软件升级的更新器 2、控制面板小程序 3、支持安装前后的镜像中制作安装包的 Advanced Repackager 4、游戏、软件、试用授权 5、导入其他 MSI 文件、Visual Studio 工程、Eclipse 工程...

    机器:机器是.NET的自然语言处理库,专注于提供用于处理资源贫乏的语言的工具

    该库当前仅提供一组基本算法,但目标是将来包含更多算法。 特征 翻译 机器提供了一组翻译引擎。 目前,它包括一个基于分支的SMT引擎和一个基于HermitCrab形态分析器的基于规则的引擎。 形态学 机器包含一个称为...

    Advanced Installer Architect 14.x Patch

    - 更多支持的功能: 1、用于软件升级的更新器 2、控制面板小程序 3、支持安装前后的镜像中制作安装包的 Advanced Repackager 4、游戏、软件、试用授权 5、Windows Mobile/CE 安装程序 6、导入其他 MSI 文件、...

    next-starter:Nextjs Starter-具有打字稿,eslint和漂亮

    要了解有关Next.js的更多信息,请查看以下资源: -了解Next.js功能和API。 交互式Next.js教程。 您可以查看-欢迎您提供反馈和意见! 立即在ZEIT上部署 部署Next.js应用程序的最简单方法是使用创建者提供的。 ...

Global site tag (gtag.js) - Google Analytics