Valid format values for declare-styleable/attr tags

Meh. Wasted an hour trying to sort this out.

The answer happened to be buried in some Android code. The fact that Android is open source is a cool thing–but I shouldn’t have to dig through that source kit just to figure out the answer to something that could be better documented.

When declaring a <declare-styleable> <attr> tag, you supply a name for the new attribute for your custom class, and you provide a format. Well, I couldn’t find the valid values for the format attribute in the documentation. But I did find them here.

And those values?

  • reference
  • string
  • color
  • dimension
  • boolean
  • integer
  • float
  • fraction
  • enum
  • flag

It also appears from the source code that this field is optional, and I presume if it is left blank, either one of two things will happen: this will default as a resource reference, or the format is only used for type checking, and this can be any value. I dunno; I haven’t tried it.

On the off-chance someone knows the answer, could they leave it in the comments?

5Pingbacks & Trackbacks on Valid format values for declare-styleable/attr tags

  1. […] The name property of the declare-stylable node should reflect the class-name of your custom View/ViewGroup. The attr node inside references the actual property you are trying to create, You can create a bunch of these properties here. The format of the property can be of the following types [via]: […]

  2. […] about the declare-styleable tag by which we can declare custom styles for components. I did find this list of valid values for the format attribute of the attr tag. While that’s nice as far as it […]

  3. […] about the declare-styleable tag by which we can declare custom styles for components. I did find this list of valid values for the format attribute of the attr tag. While that’s nice as far as it […]

Leave a Reply