Android: Is it possible to use string/enum in drawable selector?

前端 未结 3 650
小鲜肉
小鲜肉 2021-02-18 16:26

Questions

Q1: Has anyone managed to get custom string/enum attribute working in xml selectors? I got a boolean attribute working by following [1], bu

3条回答
  •  忘掉有多难
    2021-02-18 17:22

    Q1:

    I haven't tried this myself, but:

    Have you tried placing your @color/custom_button_text_color.xml in the drawable folder? (Just to be sure, there's a bit of folder magic here and there in Android and I'm not sure about this one.)

    Q2:

    There are two use cases for state sets. One is to explicitly declare selectors for stateful drawables programmatically. In this case, for selectors, you need to be able to tell Android to use this drawable if an attribute is not set. To express this, you can include the negated criteria (preceded by a minus sign) in the int[].

    While this is barely mentioned anywhere in the context of selector criteria, it is never mentioned for drawable states themselves (aka the representation of the drawable's state). So one is definitely on the safe side if one does not include negated state IDs in the set; the provided Android implementations also do not includde them.

提交回复
热议问题