【翻译】(39)样式资源

【翻译】(39)样式资源

 

see

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

 

原文见

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

 

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

 

Style Resource

 

样式资源

 

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

 

See also

 

另见

 

Styles and Themes 样式和主题

 

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

 

A style resource defines the format and look for a UI. A style can be applied to an individual View (from within a layout file) or to an entire Activity or application (from within the manifest file).

 

一个样式资源定义一个用户界面的格式和外观。一个样式可以被应用到一个单独的View(从一个布局文件中)或应用到整个Activity或应用程序(从清单文件中)。

 

For more information about creating and applying styles, please read Styles and Themes.

 

想获取关于创建和应用样式的更多信息,请阅读样式和主题。

 

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

 

Note: A style 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 style 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 element's name will be used as the resource ID.

 

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

 

* resource reference:

 

* 资源引用:

 

In XML: @[package:]style/style_name

 

在XML中:@[<包名>:]style/<样式名称>

 

* syntax:

 

* 语法:

 

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

 

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

<resources>

    <style

        name="style_name"

        parent="@[package:]style/style_to_inherit">

        <item

            name="[package:]style_property_name"

            >style_value</item>

    </style>

</resources>

 

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

 

* elements:

 

* 元素:

 

* <resources>

 

Required. This must be the root node.

 

必需的。它必须是根节点

 

No attributes.

 

无属性。

 

* <style>

 

Defines a single style. Contains <item> elements.

 

定义一个单一的样式。包含<item>元素。

 

* attributes:

 

* 属性:

 

* name

 

String. Required. A name for the style, which is used as the resource ID to apply the style to a View, Activity, or application.

 

字符串。必需的。样式的名称,它被用作资源ID以应用样式到一个View,Activity或应用程序。

 

* parent

 

Style resource. Reference to a style from which this style should inherit style properties.

 

样式资源。引用一个样式,这个样式应该从它那里继承样式属性。

 

* <item>

 

Defines a single property for the style. Must be a child of a <style> element.

 

为该样式定义一个单一的属性。必需是<style>元素的子元素。

 

* attributes:

 

* 属性:

 

* name

 

Attribute resource. Required. The name of the style property to be defined, with a package prefix if necessary (for example android:textColor).

 

属性资源。必需的。要被定义的样式属性的名称,如果需要的话带有一个包前缀(例如android:textColor)。

 

* example:

 

* 示例:

 

XML file for the style (saved in res/values/):

 

用于这个样式的XML文件(保存在res/values/中):

 

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

 

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

<resources>

    <style name="CustomText" parent="@style/Text">

        <item name="android:textSize">20sp</item>

        <item name="android:textColor">#008</item>

    </style>

</resources>

 

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

 

XML file that applies the style to a TextView (saved in res/layout/):

 

应用样式到一个TextView的XML文件(保存在res/layout/):

 

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

 

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

<EditText

    style="@style/CustomText"

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:text="Hello, World!" />

 

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

 

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/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值