What is AttributeSet and how can i use it?

前端 未结 4 534
谎友^
谎友^ 2020-12-24 00:04

What is AttributeSet in Android?

How can i use it for my custom view?

4条回答
  •  星月不相逢
    2020-12-24 00:50

    When a view is created from an XML layout, all of the attributes in XML tag are read from the resource bundle and passed to view's constructor as an AttributeSet

    Although it is possible to read values from the AttributeSetdirectly, doing so has some disadvantages:

    • Resource reference within attribute values are not resolved
    • Styles are not applied

    Instead pass AttributeSet to obtainStyledAttribute(). This method passes back TypedArray array of values that have been deferenced and styled.

提交回复
热议问题