Color State List not recognized in Shape Drawable

后端 未结 3 1172
情书的邮戳
情书的邮戳 2020-12-09 18:53

I define following drawable my_background_drawable.xml:




        
3条回答
  •  天命终不由人
    2020-12-09 19:28

    A ColorStateList cannot be passed as an attribute for in an XML definition, or really any attribute of a . This attribute is inflated out of the XML as a Color resource and then passed to the Drawable's setColor() method, which only takes a single ARGB value.

    There is only one type of Drawable instance that is designed to contain and present multiple items based on state, and that is StateListDrawable, which is what you get when you inflate a . All other Drawable instances are meant to simply be members of this collection or drawn standalone.

    Note also that an inflated item is actually a GradientDrawable and not a ShapeDrawable. If you check out the inflate() method of GradientDrawable in the source, you can get all the detail you could ask for on how each attribute is used.

    HTH!

提交回复
热议问题