I'm implementing my own <declare-styleable>
for a custom View (following the instructions here). I'd like to be able to specify an array of integers as one of the possible XML attributes. How do I:
attrs.xml
?obtainStyledAttributes()
in my custom View?You can declare it as a reference.
<declare-styleable name="MyView">
<attr name="array" format="reference"/>
</declare-styleable>
It looks like TypeArray
hasn't getIntArray
method so you have to get it directly from the resources.
final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.MyView);
final int id = array.getResourceId(R.styleable.MyView_array, 0);
if (id != 0) {
final int[] values = getResources().getIntArray(id);
}
array.recycle()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With