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.

Resources.Theme的更多相关文章

  1. Android开发之Theme、Style探索及源码浅析

    1 背景 前段时间群里有伙伴问到了关于Android开发中Theme与Style的问题,当然,这类东西在网上随便一搜一大把模板,所以关于怎么用的问题我想这里也就不做太多的说明了,我们这里把重点放在理解 ...

  2. Chapter 7 Resources in Plug-In(1)

    Activity and resource are like twin brothers. And so if the activity need to be solve in Plug-In com ...

  3. 【起航计划 005】2015 起航计划 Android APIDemo的魔鬼步伐 04 App->Activity->Custom Dialog Dialog形式的Activity,Theme的使用,Shape的使用

    App->Activity->Custom Dialog 例子使用Activity 来实现自定义对话框 类CustomDialogActivity本身无任何特别之处.关键的一点是其在And ...

  4. E/dalvikvm: Could not find class...

    logcat日志输出信息: - ::-/net.chiangfai I/dalvikvm: Could not find method android.content.res.Resources.ge ...

  5. Android 自定义view(二) —— attr 使用

    前言: attr 在前一篇文章<Android 自定义view -- attr理解>已经简单的进行了介绍和创建,那么这篇文章就来一步步说说attr的简单使用吧 自定义view简单实现步骤 ...

  6. android 入门- 词汇

    final Resources.Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes();获得自定 ...

  7. Android中插件开发篇之----应用换肤原理解析

    一.前言 今天又到周末了,感觉时间过的很快呀.又要写blog了.那么今天就来看看应用的换肤原理解析.在之前的一篇博客中我说道了Android中的插件开发篇的基础:类加载器的相关知识.没看过的同学可以转 ...

  8. Android中插件开发篇之----类加载器

    关于插件,已经在各大平台上出现过很多,eclipse插件.chrome插件.3dmax插件,所有这些插件大概都为了在一个主程序中实现比较通用的功能,把业务相关或者让可以让用户自定义扩展的功能不附加在主 ...

  9. Android-深入理解android自定义属性(AttributeSet,TypedArray)

    属性 自定义属性,首先要定义出来属性,我们新建一个attrs.xml: <?xml version="1.0" encoding="utf-8"?> ...

随机推荐

  1. ACM_Reverse Bits(反转二进制)

    Reverse Bits Time Limit: 2000/1000ms (Java/Others) Problem Description: Reverse bits of a given 32 b ...

  2. IOS开发 键盘添加工具条 退出 上一项 下一项 简单实现

    首先设置每个 UITextField 的 inputAccessoryView 为UIToolBar : 将所有的 textField 放入一个数组: 设置 UITextField UITextFie ...

  3. fastjson读取json配置文件

    fastjson读取json配置文件: ClassLoader loader=FileUtil.class.getClassLoader(); InputStream stream=loader.ge ...

  4. html5——2D转换

    transform 属性 1.向元素应用 2D 或 3D 转换 2.该属性允许我们对元素进行旋转.缩放.移动或倾斜. 缩放与位移 transform: scale(, 0.5);//水平缩放,垂直缩放 ...

  5. JS——隐式全局变量

    在函数中,var声明的是局部变量,不带var的是隐式全局变量 <script> function fn() { var a = b = c = 0;//a是局部变量,b.c是全局变量 va ...

  6. Python语言之类

    1.一个空类 #Filename : emptyclass.py class Empty: pass e = Empty() print( e ) #<__main__.Empty object ...

  7. (转) Quartz学习——SSMM(Spring+SpringMVC+Mybatis+Mysql)和Quartz集成详解(四)

    http://blog.csdn.net/u010648555/article/details/60767633 当任何时候觉你得难受了,其实你的大脑是在进化,当任何时候你觉得轻松,其实都在使用以前的 ...

  8. C# Winform 获得下拉框 选中的值

    string PrintName = cmbPrinter.SelectedIndex.ToString(); PrintName = cmbPrinter.SelectedItem.ToString ...

  9. CDR真实图片转水墨画效果制作教程

    CorelDRAW创造性滤镜组是最具有创造力的滤镜,使用里面的散开滤镜能够实现类似于水墨的表现手法,然后再结合图层的合并模式,让您的图片产生意想不到的视觉效果.本文将利用CorelDRAW软件中提供的 ...

  10. vue项目中使用百度地图的方法

    1.在百度地图申请密钥: http://lbsyun.baidu.com/  将 <script type="text/javascript" src="http: ...