How to get an enum which is created in attrs.xml in code

后端 未结 5 1849
小蘑菇
小蘑菇 2020-12-23 20:30

I created a custom View (find it here) with an declare-styleable attribute of type enum. In xml I can now choose one of the enum entries for my custom attribute. Now I want

5条回答
  •  甜味超标
    2020-12-23 20:32

    I know it's been a while since the question was posted, but I had the same issue recently. I hacked a little something together that uses Square's JavaPoet and some stuff in the build.gradle that automatically creates a Java enum class from the attrs.xml on project build.

    There's a little demo and a readme with an explanation at https://github.com/afterecho/create_enum_from_xml

    Hope it helps.

提交回复
热议问题