style和attr的 温习

来源:互联网 发布:手机ssh连接linux 编辑:程序博客网 时间:2024/06/13 22:25

android l引入了新的theme,so,你需要温习style

有这样一篇文章(所以,本文为 转载):http://www.cnblogs.com/angeldevil/p/3479431.html

之下为 总结:


attrs.xml
其中定义了,app中允许出现哪些属性

declare-styleable
声明了一些属性
形式:

<declare-styleable name="styleable1">

        <attr name="attr1" format="" />

</declare-styleable>

系统会为我们生成:

R.styleable.styleable1(为int[]类型,而其ele为 styleable1所声明的属性)

R.styleable.styleable1_attr1(该属性 在 styleable 中的索引)

声明在 styleable中的属性 和 直接在attrs.xml中定义的属性 有什么区别:

当我们自定义了一个view,可能需要为该view设置一些属性,而这些属性从哪里来:往往来自styleable(和,系统已经预先定义的属性)


style
一些 属性和其值 的集合

属性的值类型:

string,int,color等

reference

引用了什么:一个style


属性的值的来源 和 优先级:
在layout.xml中,定义 view的myappns:attr1
在layout.xml中,定义 view的style
在view.java中,指定 defStyleAttr(而当前theme会指定 该styleattr引用了哪个style)

defStyleAttr 和 defStyleRes:

出现在:public TypedArray obtainStyledAttributes (AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes)

而你可以通过:tarray.getxxx(R.styleable.styleable1_attr1);获得属性值

在view.java中,指定 defStyleRes(起作用的情形:当defStyleAttr为0 或者 defStyleAttr不为0,但是defStyleAttr并没被指定引用)
在theme中指定属性值


0 0