Resources.Theme
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, APIs to retrieve XML attributes with style and theme information applied.
int[], int, int)
您经常会使用到 obtainStyledAttributes(AttributeSet,
int[], int, int) 来检索通过 style 和 theme 应用的 xml 属性。
public TypedArray obtainStyledAttributes (AttributeSet set,
int[] attrs, int defStyleAttr, int defStyleRes)
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:
- Any attribute values in the given AttributeSet.
- The style resource specified in the AttributeSet (named "style").
- The default style specified by defStyleAttr and defStyleRes
- The base values in this theme.
- AttributeSet 中的不论什么属性值
- AttributeSet
中通过 style 属性指定的 style 资源 - 通过 defStyleAttr 和
defStyleRes 指定的值
- 主题中的基本值
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, then the button's text will always be black, regardless of what is specified in any of the styles.
textColor="#ff000000">
上面值的优先级是自顶向下逐渐变弱的。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的更多相关文章
- Android开发之Theme、Style探索及源码浅析
1 背景 前段时间群里有伙伴问到了关于Android开发中Theme与Style的问题,当然,这类东西在网上随便一搜一大把模板,所以关于怎么用的问题我想这里也就不做太多的说明了,我们这里把重点放在理解 ...
- 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 ...
- 【起航计划 005】2015 起航计划 Android APIDemo的魔鬼步伐 04 App->Activity->Custom Dialog Dialog形式的Activity,Theme的使用,Shape的使用
App->Activity->Custom Dialog 例子使用Activity 来实现自定义对话框 类CustomDialogActivity本身无任何特别之处.关键的一点是其在And ...
- E/dalvikvm: Could not find class...
logcat日志输出信息: - ::-/net.chiangfai I/dalvikvm: Could not find method android.content.res.Resources.ge ...
- Android 自定义view(二) —— attr 使用
前言: attr 在前一篇文章<Android 自定义view -- attr理解>已经简单的进行了介绍和创建,那么这篇文章就来一步步说说attr的简单使用吧 自定义view简单实现步骤 ...
- android 入门- 词汇
final Resources.Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes();获得自定 ...
- Android中插件开发篇之----应用换肤原理解析
一.前言 今天又到周末了,感觉时间过的很快呀.又要写blog了.那么今天就来看看应用的换肤原理解析.在之前的一篇博客中我说道了Android中的插件开发篇的基础:类加载器的相关知识.没看过的同学可以转 ...
- Android中插件开发篇之----类加载器
关于插件,已经在各大平台上出现过很多,eclipse插件.chrome插件.3dmax插件,所有这些插件大概都为了在一个主程序中实现比较通用的功能,把业务相关或者让可以让用户自定义扩展的功能不附加在主 ...
- Android-深入理解android自定义属性(AttributeSet,TypedArray)
属性 自定义属性,首先要定义出来属性,我们新建一个attrs.xml: <?xml version="1.0" encoding="utf-8"?> ...
随机推荐
- JS——tab切换
排它思想: 1.先让所有的元素恢复默认值 2.再让选中的元素赋专有的值 3.干掉所有人,剩下我一个 <!DOCTYPE html> <html> <head lang=& ...
- 史上巨坑: vim的"set foldmethod=syntax"设置竟然是导致ctrl+p(ctrl+n)补全在文件稍大时光标位于中间位置补全效率变慢的元凶!
最近我的vim又让我闹心了. 问题出现在supertab的补全速度上, 有时候按下tab键半天才弹出补全列表, 即便是弹出了列表在列表上下移动也变得的相当缓慢, 这让我的很是蛋疼. 在完全无法接受这个 ...
- 170925_2 Python socket 创建UDP的服务器端和客户端
[python版本]3.6 UDP服务器端: from socket import * from time import ctime host = '' port = 21567 buf_size = ...
- css图片高清适配
同一张图片,在普通屏显示正常,但高清屏出现模糊.原因是原来一个像素的点分成的四个像素的点进行了显示. 解决方案:在高清屏中把图片变成二倍图,前提是二倍的高清图已经存在. .icon{ backgrou ...
- codeforces_738C_二分
C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- C# 计算百分比
//计算比率 decimal A =(decimal) 200.20; decimal B = (decimal)1000.20; decimal t = decimal.Parse((A/B).To ...
- CI框架3.x 之实现前后端分离
一.建立合理的目录结构 admin与home为后台和前台的控制器和模板文件夹 二.定义前后台视图路径常量 在constants.php中添加如下代码: //定义前台视图路径常量 define('HOM ...
- Xamarin.Forms实现touch事件
Xamarin.Forms的View没有touch事件,只能自己实现 首先,在共享项目里面,放入这几个类,结构大概是这样的: using System; using Xamarin.Forms; na ...
- 在centos安装 sql server
主要参考官方文档https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-red-hat
- 零基础转行Linux云计算运维工程师获得20万年薪的超级学习技巧
云计算概念一旦产生便一发不可收拾,成为移动互联网时代最为火热的行业之一.国内各大互联网公司例如阿里.腾讯.百度.网易等纷纷推出自己的云计算产品,3月10日,腾讯云0.01元投标时间更是让云计算在普罗大 ...