Resources.Theme

public final class

Resources.Theme

extends  Object
java.lang.Object
   ↳ android.content.res.Resources.Theme

Class Overview


This class holds the current attribute values for a particular theme. In other words, a Theme is a set of values for resource attributes; these are used in conjunction with TypedArray to resolve the final value for an attribute.

该类保存有当前主题的所有属性值。换句话说,该类是 resource 属性值集合;为了获得一个属性的最终的值,它常和 TypedArray 联合使用。

The Theme's attributes come into play in two ways: (1) a styled attribute can explicit reference a value in the theme through the "?themeAttribute" syntax; (2) if no value has been defined for a particular styled attribute, as a last resort we will try to find that attribute's value in the Theme.

主题的属性值主要通过两种方式起作用:1.styled 属性可以通过 "?themeAttribute" 这种语法明确引用一个主题的属性值。2. styled attribute 属性没有被定义一个值,最后将在 theme 中查找改值。

You will normally use the obtainStyledAttributes(AttributeSet, int[], int, int) APIs to retrieve XML attributes with style and theme information applied.

您常常会使用到 obtainStyledAttributes(AttributeSet, int[], int, int) 来检索通过 style 和 theme 应用的 xml 属性。

public TypedArray obtainStyledAttributes (AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes)
Added in  API level 1

Return a TypedArray holding the attribute values in set that are listed in attrs. In addition, if the given AttributeSet specifies a style class (through the "style" attribute), that style will be applied on top of the base attributes it defines.

返回一个 TypedArray 来保存 attrs 列表中的属性值。另外,如果给定的 AttributeSet 通过 style 属性指定了一个 style 类,这个 style 将被应用在它定义的基础属性的最上面。

Be sure to call TypedArray.recycle() when you are done with the array.

当使用结束后一定要调用 TypedArray.recycle() 来回收相关的资源(比如 xml parser 等等)。

When determining the final value of a particular attribute, there are four inputs that come into play:

  1. Any attribute values in the given AttributeSet.
  2. The style resource specified in the AttributeSet (named "style").
  3. The default style specified by defStyleAttr and defStyleRes
  4. The base values in this theme.

     一个属性的最终值由 4 种输入方式决定:
  1. AttributeSet 中的任何属性值
  2. AttributeSet 中通过 style 属性指定的 style 资源
  3. 通过 defStyleAttr 和 defStyleRes 指定的值
  4. 主题中的基本值

Each of these inputs is considered in-order, with the first listed taking precedence over the following ones. In other words, if in the AttributeSet you have supplied <Button textColor="#ff000000">, then the button's text will always be black, regardless of what is specified in any of the styles.

上面值的优先级是自顶向下逐渐变弱的。1最高,4最弱,换句话说,1和4都指定了某个属性值,最终生效的是1中的值。

Parameters
set The base set of attribute values. May be null.
attrs The desired attributes to be retrieved.
defStyleAttr An attribute in the current theme that contains a reference to a style resource that supplies defaults values for the TypedArray. Can be 0 to not look for defaults.
defStyleRes A resource identifier of a style resource that supplies default values for the TypedArray, used only if defStyleAttr is 0 or can not be found in the theme. Can be 0 to not look for defaults.
Returns
  • Returns a TypedArray holding an array of the attribute values. Be sure to call TypedArray.recycle() when done with it.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值