0

I have the following code in the attrs.xml to use it for custom view but I want to convert it programmatically and use it in java. How will I do it? I would love to hear from you!

<declare-styleable name="BookView">
    <attr name="date_type" format="flags">
        <flag name="nen" value="0x01"/>
        <flag name="year_month" value="0x02"/>
        <flag name="year" value="0x04"/>
        <flag name="month" value="0x08"/>
    </attr>
</declare-styleable>



mCalType = attributes.getInteger(R.styleable.BookView_date_type, CALENDAR_TYPE);
Nancy
  • 129
  • 2
  • 13
  • How do you mean, exactly? You no longer want to set that property from XML attributes? If so, just create four `public static final int` fields, and a `public` setter method in your class. You can then just delete all of the XML and code for those styleable attributes. – Mike M. Nov 02 '18 at 02:15
  • Well, if you're copying this from somewhere, you might already have the necessary stuff in code, since XML attributes often correspond directly to properties in Java classes with setters/getters. You'd then just need to get rid of the styleable attribute stuff. Have a look at [my answer here](https://stackoverflow.com/a/41997425). The `RoundishImageView` class has several `public static final int CORNER_*` constants that correspond to XML attribute values, and a `setRoundedCorners()` method to set the value programmatically. – Mike M. Nov 02 '18 at 02:24

0 Answers0