`

【翻译】(34)颜色状态列表资源

 
阅读更多

【翻译】(34)颜色状态列表资源

 

see

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

 

原文见

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

 

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

 

Color State List Resource

 

颜色状态列表资源

 

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

 

See also

 

另见

 

Color (simple value)

 

颜色(简单值)

 

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

 

A ColorStateList is an object you can define in XML that you can apply as a color, but will actually change colors, depending on the state of the View object to which it is applied. For example, a Button widget can exist in one of several different states (pressed, focused, or niether) and, using a color state list, you can provide a different color during each state.

 

一个ColorStateList是一个你可以定义在XML中的对象,你可以应用它作为一个颜色,但实际上将会改变颜色,依赖于它被应用在的View对象的状态。例如,一个Button部件可以存在于几个不同状态之一(按下,获取焦点,或都不是)(注:neither貌似拼错?),并且使用一个颜色状态列表,你可以在各个状态期间提供不同的颜色。

 

You can describe the state list in an XML file. Each color is defined in an <item> element inside a single <selector> element. Each <item> uses various attributes to describe the state in which it should be used.

 

你可以在一个XML文件中描述状态列表。每个颜色定义在一个单一<selector>元素内的<item>元素中。每个<item>使用不同的属性以描述它应该被使用在的状态。

 

During each state change, the state list is traversed top to bottom and the first item that matches the current state will be used—the selection is not based on the "best match," but simply the first item that meets the minimum criteria of the state.

 

在每个状态改变期间,状态列表被由上而下遍历,并且第一个匹配当前状态的条目将被使用——选择不基于“最佳匹配”,只是简单地选择第一个满足状态最低标准的条目。

 

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

 

Note: If you want to provide a static color resource, use a simple Color value.

 

注意:如果你希望提供一个静态颜色资源,请使用一个简单Color值。

 

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

 

* file location:

 

* 文件位置:

 

res/color/filename.xml

 

res/color/<文件名>.xml

 

The filename will be used as the resource ID.

 

文件名将被用作资源ID。

 

* compiled resource datatype:

 

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

 

Resource pointer to a ColorStateList.

 

指向ColorStateList的资源指针。

 

* resource reference:

 

* 资源引用:

 

In Java: R.color.filename

 

在Java中:R.color.<文件名>

 

In XML: @[package:]color/filename

 

在XML中: @[<包名>:]color/<文件名>

 

* syntax:

 

* 语法:

 

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

 

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

<selector xmlns:android="http://schemas.android.com/apk/res/android" >

    <item

        android:color="hex_color"

        android:state_pressed=["true" | "false"]

        android:state_focused=["true" | "false"]

        android:state_selected=["true" | "false"]

        android:state_checkable=["true" | "false"]

        android:state_checked=["true" | "false"]

        android:state_enabled=["true" | "false"]

        android:state_window_focused=["true" | "false"] />

</selector>

 

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

 

* elements:

 

* 元素:

 

* <selector>

 

Required. This must be the root element. Contains one or more <item> elements.

 

必需的。它必须是根元素。包含一个或多个<item>元素。

 

* attributes:

 

* 属性:

 

* xmlns:android

 

String. Required. Defines the XML namespace, which must be "http://schemas.android.com/apk/res/android".

 

字符串。必需的。定义XML名字空间,必须是"http://schemas.android.com/apk/res/android"。

 

* <item>

 

Defines a color to use during certain states, as described by its attributes. Must be a child of a <selector> element.

 

定义在某个状态期间使用的颜色,正如它的属性所描述的状态。必须是<selector>元素的子元素。

 

* attributes:

 

* 属性:

 

* android:color

 

Hexadeximal color. Required. The color is specified with an RGB value and optional alpha channel.

 

十六进制颜色。必需的。颜色用一个RGB值(注:RGB是红绿蓝的英文首字母缩写)指定以及可选的透明通道来指定。

 

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

 

值总是用一个井号(#)(注:pound原意是英镑,#号在美式英语可读作pound sign,在其它地方称hash,在音乐中读作sharp)字符开头,并且后面是透明-红-绿-蓝信息,用以下格式之一表示。

 

* #RGB

* #ARGB

* #RRGGBB

* #AARRGGBB

 

* android:state_pressed

 

Boolean. "true" if this item should be used when the object is pressed (such as when a button is touched/clicked); "false" if this item should be used in the default, non-pressed state.

 

布尔型。"true"如果当对象被按下(诸如当一个按钮被触碰/点击)时这个条目应该被使用;"false"如果这个条目在非按下状态下默认应该被使用。

 

* android:state_focused

 

Boolean. "true" if this item should be used when the object is focused (such as when a button is highlighted using the trackball/d-pad); "false" if this item should be used in the default, non-focused state.

 

布尔型。"true"如果当对象获取焦点时(诸如当按钮使用轨迹球/方向板高亮时)这个条目应该被使用;"false"如果这个条目应该被默认使用于非获取焦点状态。

 

* android:state_selected

 

Boolean. "true" if this item should be used when the object is selected (such as when a tab is opened); "false" if this item should be used when the object is not selected.

 

布尔型。"true"如果当对象被选中时(诸如当打开标签页时)这个条目应该被使用;"false"如果当对象未选中时这个条目应该被使用。

 

* android:state_checkable

 

Boolean. "true" if this item should be used when the object is checkable; "false" if this item should be used when the object is not checkable. (Only useful if the object can transition between a checkable and non-checkable widget.)

 

布尔型。"true"如果当对象可勾选时这个条目应该被使用;"false"如果当对象不可勾选时这个条目应该被使用。(仅当对象可以在可勾选和非可勾选部件之间过渡才有用。)

 

* android:state_checked

 

Boolean. "true" if this item should be used when the object is checked; "false" if it should be used when the object is un-checked.

 

布尔型。"true"如果当对象被勾选时这个条目应该被使用;"false"如果当对象未被勾选时它应该被使用。

 

* android:state_enabled

 

Boolean. "true" if this item should be used when the object is enabled (capable of receiving touch/click events); "false" if it should be used when the object is disabled.

 

布尔型。"true"如果当对象使能时这个条目应该被使用(可以接收触碰/点击事件);"false"如果当对象被屏蔽时它应该被使用。

 

* android:state_window_focused

 

Boolean. "true" if this item should be used when the application window has focus (the application is in the foreground), "false" if this item should be used when the application window does not have focus (for example, if the notification shade is pulled down or a dialog appears).

 

布尔型。"true"如果当应用程序窗口拥有焦点时(应用程序在前台)这个条目应该被使用,"false"如果当应用程序不拥有焦点时这个条目应该被应用(例如,如果通知窗帘被拉下或一个对话框显示)。

 

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

 

Note: Remember that the first item in the state list that matches the current state of the object will be applied. So if the first item in the list contains none of the state attributes above, then it will be applied every time, which is why your default value should always be last (as demonstrated in the following example).

 

注意:记住在状态列表中第一个匹配对象当前状态的条目将被应用。所以如果列表中第一个条目没有包含上面所述的任何状态属性,那么它将每次都会被应用,这就是为什么你的默认值应该总是放在最后(正如下面的示例中所演示的那样)。

 

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

 

* example:

 

* 示例:

 

XML file saved at res/color/button_text.xml:

 

XML文件保存在res/color/button_text.xml:

 

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

 

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

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true"

          android:color="#ffff0000"/> <!-- pressed --> <!-- 按下 -->

    <item android:state_focused="true"

          android:color="#ff0000ff"/> <!-- focused --> <!-- 获取焦点 -->

    <item android:color="#ff000000"/> <!-- default --> <!-- 默认 -->

</selector>

 

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

 

This layout XML will apply the color list to a View:

 

这个布局XML将应用颜色列表到一个View:

 

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

 

<Button

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:text="@string/button_text"

    android:textColor="@color/button_text" />

 

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

 

* see also:

 

* 另见:

 

* Color (simple value) 颜色(简单值)

* ColorStateList 

* State List Drawable 状态列表可绘画对象

 

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 - 13 Jan 2012 0:46

 

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

 

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/

 

分享到:
评论

相关推荐

    支持状态栏显示输入法状态 ,屏幕取色功能 ,JSON格式化, 翻译.zip

    这个压缩包文件中的资源,包括“支持状态栏显示输入法状态”、“屏幕取色功能”以及“JSON格式化”和“翻译”相关的工具,都是开发者在进行快应用开发时可能需要用到的实用功能。 首先,让我们来探讨“支持状态栏...

    Android studio项目颜色选择器

    为了深入理解这个项目,开发者需要查看这些源码,了解如何处理颜色选择、状态保存、屏幕旋转和多语言支持的细节。 总的来说,这个"Android Studio项目颜色选择器"涵盖了Android开发中的多个关键知识点,包括...

    C# GD+文献翻译

    这篇文献翻译中,读者将能够深入理解如何利用C#的GDI+功能创建动态的用户界面,进行图像处理,以及如何有效地管理图形资源。对于Windows应用程序开发人员来说,掌握GDI+技术是提高应用视觉质量和性能的关键。通过...

    GDI+ SDK参考(翻译版本高清)

    本资源为"GDI+ SDK参考(翻译版本高清)"的PDF文档,包含了详尽的GDI+编程接口和使用指南。 GDI+的核心概念主要包括绘图对象、设备上下文、图形路径、颜色管理以及图像处理。以下将详细讲解这些关键知识点: 1. 绘图...

    lazyfoo SDL游戏入门教程 紫冀魔王 翻译版

    《lazyfoo SDL游戏入门教程 紫翼魔王 翻译版》是一份专为初学者设计的游戏开发教程,由知名游戏开发资源提供者lazyfoo的原版教程翻译而来,紫翼魔王负责了中文版的翻译工作,使得国内的学习者能够更加方便地理解和...

    MaterialDesign中文协同翻译

    同时,颜色还可以表达状态,如警告、成功或信息提示。 此外,Material Design有一套标准化的图标、按钮、输入框等组件,称为“组件系统”。这些组件遵循一致的尺寸、间距和样式规则,确保了整个系统的统一性和可...

    CEGUI官方资料翻译

    这包括设置材质、纹理、颜色和几何形状,以及处理透明度和光照效果。学习CEGUI渲染涉及理解渲染上下文、纹理管理和渲染状态的管理。 2. **资源管理入门**:在CEGUI中,资源是图像、字体、布局文件等的集合,它们被...

    QQ截图QQScreenShotV2.4.1支持翻译图片识别画笔图钉等功能

    I18N目录可能包含了多语言资源,Resource.9.5.4.28063则可能是一个资源包,包含了软件的各种图标、提示文本等。 总的来说,QQ截图QQScreenShotV2.4.1是一个功能全面、易于使用的截图工具,它结合了强大的图像处理和...

    Quartz2Dprograming翻译

    "Quartz 2D programming翻译.docx"文件很可能是对官方文档或书籍的中文翻译,对于想要深入理解和学习Quartz 2D的开发者来说,这将是一个宝贵的资源,可以帮助他们更好地掌握这一强大的图形绘制技术。

    Quest3d所有channel中文翻译

    ### Quest3d所有channel中文翻译知识点详解 #### 骨骼 (Bone) - **功能**:用于处理模型中的骨骼动画,使模型能够按照预设的动作进行动态展示。 - **应用场景**:角色动画、游戏开发。 #### 亮度对比度伽马调整 ...

    GAMMA最新操作手册-中文翻译版.zip

    这个中文翻译版的操作手册是学习和使用GAMMA的重要资源,通过仔细阅读和实践,用户能够高效地利用GAMMA进行数据分析和建模工作。对于IT专业人士而言,掌握GAMMA将极大地提升他们在地理信息系统、环境科学、城市规划...

    MSDN中d3d的中文翻译

    10. 状态对象(State Object):控制Direct3D的各种状态,如混合模式、深度测试、裁剪等,可以通过设置状态对象来快速切换渲染配置。 通过这份中文翻译,开发者可以了解Direct3D的基本概念、使用方法以及最佳实践,...

    UDK编辑器翻译,UDK中英文对比

    ### UDK编辑器翻译与中英对比:深入解析与应用 #### UDK编辑器概览 UDK(Unreal Development Kit)是Epic Games提供的一个免费版本的Unreal Engine 3,它允许开发者创建和发布游戏,而无需支付授权费用。在游戏...

    iTween帮助文档中英翻译

    翻译方面,"iTween帮助文档中英翻译"表明这个压缩包包含了iTween的中文和英文版帮助文档,这对于国内开发者来说是一份宝贵的资源。通过阅读这些文档,开发者不仅可以了解每个函数的具体用法,还能掌握如何结合自己的...

    ios 城市列表选择

    - 控件的设计应考虑可定制性,如字体、颜色、选中状态的样式等,以便适应不同应用的视觉风格。 2. **数据管理**: - 城市数据可以存储为JSON文件或数据库,加载时读取并转化为可使用的数据结构,如数组或字典。...

    采用 微拟物 FUI & Material 设计的向 bilibili 直播间发送 Vtuber 翻译、歌词的弹幕同传工具

    从文件名称列表来看,"material-douden-tool_main.zip"可能是主程序文件,包含了项目的源代码和其他资源。"说明.txt"可能包含有关如何使用工具、安装步骤、配置说明等详细信息。 在实际应用中,这样的工具可能涉及...

    unity 3d中文翻译

    这个"unity 3d中文翻译"资源显然为那些中文为母语的学习者提供了理解这款工具的重要帮助。下面将详细阐述Unity 3D的一些关键知识点。 1. **基础概念**: - **场景(Scene)**:在Unity中,每个游戏或应用都是由一...

    MagickWand函数中文翻译

    ### MagickWand函数中文翻译与解释 #### 一、引言 `MagickWand`是ImageMagick库的一部分,该库提供了一系列用于图像处理的功能。`MagickWand`接口设计为更易于使用,尤其是对于PHP开发者而言,它允许进行复杂的图像...

    Android中文翻译组——Android开发者指南(1)

    这篇由Android中文翻译组编译的文档集是初学者和经验丰富的开发者了解Android系统、构建应用程序的重要参考资料。以下是对这份指南中的主要知识点的详细阐述: 1. **Android系统架构**:Android系统分为四个主要...

    GDI+ SDK参考(翻译版本).rar

    6. **图形状态**:GDI+维护了图形状态,如绘图颜色、笔刷、剪切区域等,可以通过Save和Restore方法保存和恢复当前状态。 7. **文本布局和排版**:TextRenderer类提供了高质量的文本渲染,而StringFormat类可以控制...

Global site tag (gtag.js) - Google Analytics