首页 > 移动平台 > 详细

Android_TypedArray和obtainStyledAttributes使用

时间:2015-03-26 23:17:40      阅读:391      评论:0      收藏:0      [点我收藏+]

TypedArray实例是个属性的容器,context.obtainStyledAttributes()方法返回得到。AttributeSet是节点的属性集合.

这里的自定义属性的format,可以有很多种:

  • reference
  • string
  • color
  • dimension
  • boolean
  • integer
  • float
  • fraction
  • enum
  • flag  

context.obtainStyledAttributes(AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes)

返回一个设计样式属性包含了set里面的attrs参数:

接着是提取属性的优先级:

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.

第一优先级:AttributeSet里指定的属性

。二。。。:在AttributeSet里指定的名为"style"的风格资源(这个和第一点的区别不知道是不是整体和个别的区别以后用到的再研究下)

。三。。。:由参数defStyleAttr和defStyleRes指定的默认属性(PS:这样设计或许是为了可以自定义一个接口名在这以后想替换的时候把前面两个参数补全就行)

。四。。。:主题默认

 

xml里的显示定义如   bar:attr1="12345" > xml里的style定义如:android:style=@style/test > 当前theme > 备用Style。

Android_TypedArray和obtainStyledAttributes使用

原文:http://www.cnblogs.com/wangziqiang/p/4370232.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!