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. cglib动态代理(即AOP)

    Computer.java package com.wh.spring_aop; public class Computer { public void playLOL(){ System.out.p ...

  2. Zookeeper概念学习系列之zookeeper的角色

    详细,见如下图 1.领导者(leader) : 负责进行投票的发起和决议,更新系统状态. 2.学习者(learner): 包括跟随者(follower)和观察者(observer). 跟随者(foll ...

  3. T-SQL查询基础

    今天来带大家了解下在sql server 中的查询机制 使用select语句进行查询 1.查询所有的数据行和列 select * from student 2.查询部分行和列 select scode ...

  4. cplusplus系列>utility>pair

    http://www.cplusplus.com/reference/utility/pair/ 用于存储一对异构对象 // Compile: g++ -std=c++11 pair.cpp #inc ...

  5. linux php全能环境一键安装,小白福利!

    phpStudy Linux版&Win版同步上线 支持Apache/Nginx/Tengine/Lighttpd/IIS7/8/6 phpStudy for Linux 支持Apache/Ng ...

  6. Android之Glide获取图片Path和Glide获取图片Bitmap

    今天主要研究了Glide获取图片Path.Bitmap用法,相信也困扰了大家很久,我在网上也找了很久,基本没有,后来研究了下,也参考了下api文档,总结了以下几个方式: 1. 获取Bitmap: 1) ...

  7. 联想 K5 Note(L38012)免解锁BL 免rec 保留数据 ROOT Magisk Xposed 救砖 ZUI3.9.218

    >>>重点介绍<<< 第一:本刷机包可卡刷可线刷,刷机包比较大的原因是采用同时兼容卡刷和线刷的格式,所以比较大第二:[卡刷方法]卡刷不要解压刷机包,直接传入手机后用 ...

  8. Android项目实战_手机安全卫士拦截骚扰

    ###1.骚扰拦截需求分析1.界面1.1 黑名单列表界面1.2 添加黑名单界面2.功能2.1 黑名单的添加.删除2.2 拦截电话2.3 拦截短信 ###2.黑名单数据库的创建1.分析需要的字段id 主 ...

  9. PHP 之CURL请求封装GET、POST、PUT、DELETE

    /** * @Description: curl请求 * @Author: Yang * @param $url * @param null $data * @param string $method ...

  10. 《C++ Primer 第5版》第1章

    1.1 一个简单的C++程序 #include <iostream>int main() {    std::cout << "Hello World!" ...