在通过xml文件构造view组件的时候,往往都要使用到AttributeSet和defStyle这个两个参数,例如Button组件的构造方法Button(Context ctx, AttributeSet attrs, int defStyle)中,ctx会调用obtainStyledAttributes( AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes)方法获得一个TypedArray,然后根据这个TypeArray来设置组件的属性。obtainStyledAttributes这类方法有好几个,真正的实现是Resources.Theme类,分别是:
(1) obtainStyledAttributes( AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) : TypedArray (2) obtainStyledAttributes( int resid, int[] attrs) : TypeArray (3) obtainStyledAttributes(int[] attrs) : TypeArray