自定义组件<二> : TypeArray的用法与介绍
来源:互联网 发布:淘宝备份模板找不到了 编辑:程序博客网 时间:2024/06/05 07:35
Return a StyledAttributes 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.
Be sure to call StyledAttributes.recycle() when you are done with the array.
When determining the final value of a particular attribute, there are four inputs that come into play:
其意为:
其中resource是跟标签,可以在里面定义若干个declare-styleable,<declare-styleable name="MyView">中name定义了变量的名称,下面可以再自定义多个属性,针对<attr name="myTextSize" format="dimension"/>来说,其属性的名称为"myTextSize",format指定了该属性类型为dimension,只能表示字体的大小。
format还可以指定其他的类型比如;
reference 表示引用,参考某一资源ID
string 表示字符串
color 表示颜色值
dimension 表示尺寸值
boolean 表示布尔值
integer 表示整型值
float 表示浮点值
fraction 表示百分数
enum 表示枚举值
flag 表示位运算
最后要调用ReCycle()方法。
注意的是既然是自定义组件,一定要在XML文件中写入:
xmlns:app="http://schemas.android.com/apk/res/com.xxx(包名)"
否则报错的话,就是未写入它引起的。
在下面的环节中,会详细的介绍自定义组件的用法
- 自定义组件<二> : TypeArray的用法与介绍
- AttributeSet与TypeArray的关系
- 关于自定义属性typearray的一些小理解
- TypeArray的理解
- 自定义属性(styleable,TypeArray,obtainStyledAttributes)
- 自定义组件之属性(Property)的性质(Attribute)介绍(二)
- 自定义组件之属性(Property)的性质(Attribute)介绍(二)
- 自定义使用Adapter的组件(二)
- 自定义文本编辑组件(二)
- 自定义组件(二)
- Recycler自定义组件二
- 自定义组件(二)
- 自定义组件(二)------使用系统控件组合的自定义控件
- 四大组件基本用法与介绍(1)--activity
- 四大组件基本用法与介绍(2)-- BroadcastReceiver
- Toolbar的介绍与用法
- Toolbar的介绍与用法
- c_str()的介绍与用法
- Java计算时间差(两个时间相减)
- mongodb入门教程
- 3D语音天气球——在Unity中使用Android语音服务
- 30本程序员必读经典
- 题目60 谁获得了最高奖学金
- 自定义组件<二> : TypeArray的用法与介绍
- Android中的sp和wp指针
- Codeforces Round #283 (Div. 2) C. Removing Columns
- 详解Linux2.6内核中基于platform机制的驱动模型 (经典)
- 物联1132课程设计三
- 第0篇 设计模式初学
- springMvc 的参数验证 BindingResult result 的使用
- 图————思维导图
- 国际C语言乱码大赛(IOCCC)经典之作