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?

8 thoughts on “Valid format values for declare-styleable/attr tags

  1. Pingback: Android Custom Layouts: Custom Attributes and LayoutParams | code zen

  2. Pingback: Declaring styleable attributes in Android | Question and answer

  3. Pingback: Declaring styleable attributes in Android - Android Questions - Developers Q & A

  4. Pingback: Validformatvaluesfordeclare-styleable/attrtags[转] - Android教程 - 开发者

  5. Pingback: Valid format values for declare-styleable/attr tags[转] - Android - 开发者第2275641个问答

  6. Pingback: [android] Android에서 스타일 지정 가능한 속성 선언 - 리뷰나라

  7. Pingback: [Solved] Declaring styleable attributes in Android

  8. Pingback: Declaring styleable attributes in Android - PhotoLens

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s